Skip to content

Commit

Permalink
UBERF-7165: Backup improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
  • Loading branch information
haiodo committed Jun 24, 2024
1 parent a251f39 commit 9d7b7d8
Show file tree
Hide file tree
Showing 32 changed files with 1,307 additions and 661 deletions.
23 changes: 21 additions & 2 deletions dev/tool/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,14 +592,28 @@ export function devTool (
.description('dump workspace transactions and minio resources')
.option('-i, --include <include>', 'A list of ; separated domain names to include during backup', '*')
.option('-s, --skip <skip>', 'A list of ; separated domain names to skip during backup', '')
.option(
'-ct, --contentTypes <contentTypes>',
'A list of ; separated content types for blobs to skip download if size >= limit',
''
)
.option('-bl, --blobLimit <blobLimit>', 'A blob size limit in megabytes (default 15mb)', '15')
.option('-f, --force', 'Force backup', false)
.option('-c, --recheck', 'Force hash recheck on server', false)
.option('-t, --timeout <timeout>', 'Connect timeout in seconds', '30')
.action(
async (
dirName: string,
workspace: string,
cmd: { skip: string, force: boolean, recheck: boolean, timeout: string, include: string }
cmd: {
skip: string
force: boolean
recheck: boolean
timeout: string
include: string
blobLimit: string
contentTypes: string
}
) => {
const storage = await createFileBackupStorage(dirName)
await backup(toolCtx, transactorUrl, getWorkspaceId(workspace, productId), storage, {
Expand All @@ -608,7 +622,12 @@ export function devTool (
include: cmd.include === '*' ? undefined : new Set(cmd.include.split(';').map((it) => it.trim())),
skipDomains: (cmd.skip ?? '').split(';').map((it) => it.trim()),
timeout: 0,
connectTimeout: parseInt(cmd.timeout) * 1000
connectTimeout: parseInt(cmd.timeout) * 1000,
blobDownloadLimit: parseInt(cmd.blobLimit),
skipBlobContentTypes: cmd.contentTypes
.split(';')
.map((it) => it.trim())
.filter((it) => it.length > 0)
})
}
)
Expand Down
2 changes: 1 addition & 1 deletion models/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ export class TAttachedDoc extends TDoc implements AttachedDoc {
export class TBlob extends TDoc implements Blob {
@Prop(TypeString(), core.string.Blob)
@ReadOnly()
@Index(IndexKind.Indexed)
provider!: string

@Prop(TypeString(), core.string.BlobContentType)
@ReadOnly()
@Index(IndexKind.Indexed)
contentType!: string

@Prop(TypeString(), core.string.BlobStorageId)
Expand Down
8 changes: 4 additions & 4 deletions models/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ import {
TSpace,
TSpaceType,
TSpaceTypeDescriptor,
TTypedSpace,
TSystemSpace
TSystemSpace,
TTypedSpace
} from './security'
import { TStatus, TStatusCategory, TDomainStatusPlaceholder } from './status'
import { defineSpaceType } from './spaceType'
import { TDomainStatusPlaceholder, TStatus, TStatusCategory } from './status'
import { TUserStatus } from './transient'
import {
TTx,
Expand All @@ -103,7 +104,6 @@ import {
TTxUpdateDoc,
TTxWorkspaceEvent
} from './tx'
import { defineSpaceType } from './spaceType'

export { coreId } from '@hcengineering/core'
export * from './core'
Expand Down
2 changes: 1 addition & 1 deletion packages/presentation/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default plugin(presentationId, {
CollaboratorApiUrl: '' as Metadata<string>,
Token: '' as Metadata<string>,
FrontUrl: '' as Asset,
PreviewConfig: '' as Metadata<PreviewConfig>
PreviewConfig: '' as Metadata<PreviewConfig | undefined>
},
status: {
FileTooLarge: '' as StatusCode
Expand Down
33 changes: 17 additions & 16 deletions packages/presentation/src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,9 @@ const defaultPreview = (): ProviderPreviewConfig => ({
- contentTypes - a ',' separated list of content type patterns.
*/
export function parsePreviewConfig (config?: string): PreviewConfig {
export function parsePreviewConfig (config?: string): PreviewConfig | undefined {
if (config === undefined) {
// TODO: Remove after all migrated
return {
default: defaultPreview(),
previewers: {
'': [
{
providerId: '',
contentTypes: ['image/gif', 'image/apng', 'image/svg'], // Disable gif and apng format preview.
formats: [],
previewUrl: ''
}
]
}
}
return
}
const result: PreviewConfig = { previewers: {} }
const nolineData = config
Expand Down Expand Up @@ -99,7 +86,21 @@ export function parsePreviewConfig (config?: string): PreviewConfig {
}

export function getPreviewConfig (): PreviewConfig {
return getMetadata(presentation.metadata.PreviewConfig) as PreviewConfig
return (
(getMetadata(presentation.metadata.PreviewConfig) as PreviewConfig) ?? {
default: defaultPreview(),
previewers: {
'': [
{
providerId: '',
contentTypes: ['image/gif', 'image/apng', 'image/svg'], // Disable gif and apng format preview.
formats: [],
previewUrl: ''
}
]
}
}
)
}

export async function getBlobRef (
Expand Down
14 changes: 12 additions & 2 deletions packages/storage/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@

import {
type Blob,
type Branding,
type DocumentUpdate,
type MeasureContext,
type Ref,
type StorageIterator,
type WorkspaceId,
type WorkspaceIdWithUrl,
type Branding
type WorkspaceIdWithUrl
} from '@hcengineering/core'
import type { BlobLookup } from '@hcengineering/core/src/classes'
import { type Readable } from 'stream'
Expand Down Expand Up @@ -103,6 +104,8 @@ export interface StorageAdapterEx extends StorageAdapter {
objectName: string,
provider?: string
) => Promise<void>

find: (ctx: MeasureContext, workspaceId: WorkspaceId) => StorageIterator
}

/**
Expand All @@ -120,6 +123,13 @@ export class DummyStorageAdapter implements StorageAdapter, StorageAdapterEx {
return false
}

find (ctx: MeasureContext, workspaceId: WorkspaceId): StorageIterator {
return {
next: async (ctx) => undefined,
close: async (ctx) => {}
}
}

async listBuckets (ctx: MeasureContext, productId: string): Promise<BucketInfo[]> {
return []
}
Expand Down
2 changes: 1 addition & 1 deletion packages/text/src/nodes/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const ImageNode = Node.create<ImageOptions>({
if (fileId != null) {
const setBrokenImg = setTimeout(() => {
imgElement.src = this.options.loadingImgSrc ?? `platform://platform/files/workspace/?file=${fileId}`
}, 200)
}, 500)
if (fileId != null) {
void this.options.getBlobRef(fileId).then((val) => {
clearTimeout(setBrokenImg)
Expand Down
Loading

0 comments on commit 9d7b7d8

Please sign in to comment.