@open-pencil/cloud 0.0.0-stage → 0.17.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/LICENSE-MIT +21 -0
- package/NOTICE +7 -0
- package/README.md +37 -2
- package/dist/bin/ai-relay.d.mts +1 -0
- package/dist/bin/ai-relay.mjs +31 -0
- package/dist/bin/ai-relay.mjs.map +1 -0
- package/dist/bin/server.d.mts +1 -0
- package/dist/bin/server.mjs +29 -0
- package/dist/bin/server.mjs.map +1 -0
- package/dist/client.d.ts +1520 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +1917 -0
- package/dist/client.js.map +1 -0
- package/dist/contract.d.ts +2 -0
- package/dist/contract.js +2 -0
- package/dist/contract2.js +1453 -0
- package/dist/contract2.js.map +1 -0
- package/dist/email.d.ts +169 -0
- package/dist/email.d.ts.map +1 -0
- package/dist/email.js +670 -0
- package/dist/email.js.map +1 -0
- package/dist/index.d.ts +1755 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/listen.mjs +1881 -0
- package/dist/listen.mjs.map +1 -0
- package/dist/runtime-node.d.mts +10040 -0
- package/dist/runtime-node.d.mts.map +1 -0
- package/dist/runtime-node.mjs +32 -0
- package/dist/runtime-node.mjs.map +1 -0
- package/dist/server.d.ts +12792 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +8475 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +8324 -0
- package/dist/server.mjs.map +1 -0
- package/dist/server2.mjs +505 -0
- package/dist/server2.mjs.map +1 -0
- package/package.json +124 -4
- package/src/admin/api/routes.ts +223 -0
- package/src/admin/api/security.ts +12 -0
- package/src/admin/audit/service.ts +138 -0
- package/src/admin/email/service.ts +140 -0
- package/src/admin/enrollment/email.ts +77 -0
- package/src/admin/enrollment/service.ts +308 -0
- package/src/admin/errors.ts +20 -0
- package/src/admin/index.ts +19 -0
- package/src/admin/list.ts +61 -0
- package/src/admin/operations/service.ts +70 -0
- package/src/admin/schema.ts +28 -0
- package/src/admin/users/service.ts +369 -0
- package/src/ai-relay/app.ts +251 -0
- package/src/ai-relay/config.ts +120 -0
- package/src/ai-relay/db/index.ts +10 -0
- package/src/ai-relay/db/migrate.ts +32 -0
- package/src/ai-relay/db/migrations/001_usage.ts +26 -0
- package/src/ai-relay/db/schema.ts +20 -0
- package/src/ai-relay/index.ts +18 -0
- package/src/ai-relay/metering.ts +68 -0
- package/src/ai-relay/usage.ts +115 -0
- package/src/client/ai.ts +96 -0
- package/src/client/api.ts +528 -0
- package/src/client/auth/client.ts +188 -0
- package/src/client/auth/failure.ts +54 -0
- package/src/client/auth/navigation.ts +45 -0
- package/src/client/device-authorization.ts +134 -0
- package/src/client/discovery.ts +105 -0
- package/src/client/images.ts +81 -0
- package/src/client/index.ts +53 -0
- package/src/client/portal/account.ts +183 -0
- package/src/client/portal/administration.ts +130 -0
- package/src/client/portal/client.ts +18 -0
- package/src/client/portal/request.ts +115 -0
- package/src/client/response.ts +51 -0
- package/src/client/workspaces.ts +142 -0
- package/src/contract/account.ts +204 -0
- package/src/contract/admin/index.ts +187 -0
- package/src/contract/ai.ts +150 -0
- package/src/contract/collaboration.ts +45 -0
- package/src/contract/discovery.ts +81 -0
- package/src/contract/documents.ts +265 -0
- package/src/contract/entitlements.ts +28 -0
- package/src/contract/index.ts +204 -0
- package/src/contract/links.ts +87 -0
- package/src/contract/portal.ts +11 -0
- package/src/contract/relay.ts +368 -0
- package/src/contract/sharing.ts +191 -0
- package/src/contract/versions.ts +87 -0
- package/src/contract/workspaces.ts +100 -0
- package/src/email/index.ts +14 -0
- package/src/email/render.ts +276 -0
- package/src/email/schema.ts +144 -0
- package/src/email/templates/brand.ts +105 -0
- package/src/email/templates/document-invitation.ts +35 -0
- package/src/email/templates/enrollment.ts +27 -0
- package/src/email/templates/layout.ts +18 -0
- package/src/runtime/cloudflare/email.ts +70 -0
- package/src/runtime/cloudflare/environment.ts +57 -0
- package/src/runtime/cloudflare/index.ts +3 -0
- package/src/runtime/cloudflare/relay.ts +136 -0
- package/src/runtime/cloudflare/site.ts +13 -0
- package/src/runtime/cloudflare/tsconfig.json +21 -0
- package/src/runtime/cloudflare/worker.ts +160 -0
- package/src/runtime/node/admin.ts +59 -0
- package/src/runtime/node/ai-relay/main.ts +35 -0
- package/src/runtime/node/ai-relay/server.ts +63 -0
- package/src/runtime/node/application.ts +50 -0
- package/src/runtime/node/bootstrap.ts +22 -0
- package/src/runtime/node/cleanup.ts +24 -0
- package/src/runtime/node/command.ts +17 -0
- package/src/runtime/node/config.ts +16 -0
- package/src/runtime/node/email/runtime.ts +43 -0
- package/src/runtime/node/email/transport.ts +112 -0
- package/src/runtime/node/entitlements/main.ts +41 -0
- package/src/runtime/node/entitlements/refusal.ts +15 -0
- package/src/runtime/node/index.ts +25 -0
- package/src/runtime/node/listen.ts +35 -0
- package/src/runtime/node/main.ts +29 -0
- package/src/runtime/node/migrate.ts +13 -0
- package/src/runtime/node/quota-reconcile.ts +9 -0
- package/src/runtime/node/relay.ts +54 -0
- package/src/runtime/node/server.ts +121 -0
- package/src/runtime/node/site.ts +64 -0
- package/src/runtime/postgres/database.ts +19 -0
- package/src/runtime/s3/objects.ts +244 -0
- package/src/runtime/site/server.ts +82 -0
- package/src/server/account/actions.ts +66 -0
- package/src/server/account/routes.ts +300 -0
- package/src/server/ai/errors.ts +7 -0
- package/src/server/ai/index.ts +4 -0
- package/src/server/ai/keys.ts +43 -0
- package/src/server/ai/routes.ts +43 -0
- package/src/server/ai/service.ts +70 -0
- package/src/server/api/index.ts +8 -0
- package/src/server/api/router.ts +117 -0
- package/src/server/api/types.ts +7 -0
- package/src/server/app.ts +375 -0
- package/src/server/auth/account.ts +73 -0
- package/src/server/auth/activity.ts +213 -0
- package/src/server/auth/adapter.ts +79 -0
- package/src/server/auth/email.ts +125 -0
- package/src/server/auth/endpoints.ts +57 -0
- package/src/server/auth/factory.ts +583 -0
- package/src/server/auth/index.ts +17 -0
- package/src/server/auth/mfa-assurance.ts +55 -0
- package/src/server/auth/runtime.ts +26 -0
- package/src/server/auth/session.ts +19 -0
- package/src/server/auth/social-providers.ts +55 -0
- package/src/server/auth/user-agent.ts +16 -0
- package/src/server/auth/workspace-access.ts +23 -0
- package/src/server/cleanup/configured.ts +38 -0
- package/src/server/cleanup/documents.ts +231 -0
- package/src/server/cleanup/index.ts +29 -0
- package/src/server/cleanup/objects.ts +27 -0
- package/src/server/cleanup/revisions.ts +232 -0
- package/src/server/cleanup/uploads.ts +129 -0
- package/src/server/cleanup/worker.ts +79 -0
- package/src/server/collaboration/index.ts +28 -0
- package/src/server/collaboration/relay/authorize.ts +53 -0
- package/src/server/collaboration/relay/awareness.ts +104 -0
- package/src/server/collaboration/relay/documents.ts +39 -0
- package/src/server/collaboration/relay/hub.ts +524 -0
- package/src/server/collaboration/relay/index.ts +15 -0
- package/src/server/collaboration/relay/persistence.ts +48 -0
- package/src/server/collaboration/routes.ts +77 -0
- package/src/server/collaboration/service.ts +188 -0
- package/src/server/config/deployment.ts +178 -0
- package/src/server/config/index.ts +20 -0
- package/src/server/config/limits.ts +8 -0
- package/src/server/config/public.ts +66 -0
- package/src/server/config/schema.ts +512 -0
- package/src/server/db/database.ts +15 -0
- package/src/server/db/expressions.ts +13 -0
- package/src/server/db/index.ts +21 -0
- package/src/server/db/migrate.ts +177 -0
- package/src/server/db/migrations/001_foundation.ts +164 -0
- package/src/server/db/migrations/002_upload_cleanup_claims.ts +34 -0
- package/src/server/db/migrations/003_document_cleanup_claims.ts +23 -0
- package/src/server/db/migrations/004_document_sharing.ts +82 -0
- package/src/server/db/migrations/005_document_collaboration_epoch.ts +13 -0
- package/src/server/db/migrations/006_invitation_continuation.ts +27 -0
- package/src/server/db/migrations/007_collaboration_state.ts +25 -0
- package/src/server/db/migrations/008_storage_reservations.ts +37 -0
- package/src/server/db/migrations/009_workspace_entitlements.ts +22 -0
- package/src/server/db/migrations/010_upload_finalization.ts +22 -0
- package/src/server/db/migrations/011_upload_finalization_lease.ts +12 -0
- package/src/server/db/migrations/012_transactional_email.ts +48 -0
- package/src/server/db/migrations/013_admin_enrollment.ts +54 -0
- package/src/server/db/migrations/014_enrollment_email_kinds.ts +30 -0
- package/src/server/db/migrations/015_cloud_rate_limit.ts +22 -0
- package/src/server/db/migrations/016_auth_schema.ts +16 -0
- package/src/server/db/migrations/017_authentication_email_kinds.ts +32 -0
- package/src/server/db/migrations/018_authentication_mfa.ts +78 -0
- package/src/server/db/migrations/019_better_auth_account_issuer.ts +42 -0
- package/src/server/db/migrations/020_workspace_invitations.ts +57 -0
- package/src/server/db/migrations/021_document_versions.ts +66 -0
- package/src/server/db/migrations/022_entitlement_external_version.ts +17 -0
- package/src/server/db/migrations/023_document_images.ts +61 -0
- package/src/server/db/migrations/024_account_activity.ts +66 -0
- package/src/server/db/migrations/025_table_names.ts +58 -0
- package/src/server/db/migrations/026_user_picture.ts +30 -0
- package/src/server/db/migrations/027_document_kind.ts +19 -0
- package/src/server/db/migrations/helpers.ts +78 -0
- package/src/server/db/tables.ts +394 -0
- package/src/server/documents/access.ts +103 -0
- package/src/server/documents/errors.ts +16 -0
- package/src/server/documents/images.ts +407 -0
- package/src/server/documents/index.ts +14 -0
- package/src/server/documents/limits.ts +57 -0
- package/src/server/documents/repository.ts +141 -0
- package/src/server/documents/routes.ts +239 -0
- package/src/server/documents/service.ts +597 -0
- package/src/server/documents/summary.ts +37 -0
- package/src/server/documents/types.ts +14 -0
- package/src/server/documents/versions/checkpoint.ts +98 -0
- package/src/server/documents/versions/history.ts +25 -0
- package/src/server/documents/versions/index.ts +4 -0
- package/src/server/documents/versions/routes.ts +112 -0
- package/src/server/documents/versions/service.ts +397 -0
- package/src/server/email/crypto.ts +57 -0
- package/src/server/email/index.ts +18 -0
- package/src/server/email/invitations.ts +30 -0
- package/src/server/email/service.ts +245 -0
- package/src/server/email/types.ts +56 -0
- package/src/server/email/worker.ts +33 -0
- package/src/server/index.ts +279 -0
- package/src/server/internal/index.ts +8 -0
- package/src/server/internal/routes.ts +41 -0
- package/src/server/internal/schema.ts +10 -0
- package/src/server/internal/service.ts +44 -0
- package/src/server/invitations/index.ts +6 -0
- package/src/server/invitations/types.ts +30 -0
- package/src/server/objects/index.ts +16 -0
- package/src/server/objects/types.ts +81 -0
- package/src/server/pictures/index.ts +9 -0
- package/src/server/pictures/provider.ts +61 -0
- package/src/server/pictures/routes.ts +21 -0
- package/src/server/pictures/service.ts +235 -0
- package/src/server/policy/configured.ts +23 -0
- package/src/server/policy/database.ts +108 -0
- package/src/server/policy/entitlements.ts +29 -0
- package/src/server/policy/index.ts +17 -0
- package/src/server/policy/keys.ts +23 -0
- package/src/server/policy/policy.ts +117 -0
- package/src/server/policy/provider.ts +67 -0
- package/src/server/policy/schema.ts +69 -0
- package/src/server/policy/service.ts +85 -0
- package/src/server/policy/static.ts +62 -0
- package/src/server/quota/index.ts +7 -0
- package/src/server/quota/reconcile.ts +61 -0
- package/src/server/quota/storage.ts +165 -0
- package/src/server/rate-limit/cleanup.ts +16 -0
- package/src/server/rate-limit/index.ts +12 -0
- package/src/server/rate-limit/keys.ts +38 -0
- package/src/server/rate-limit/middleware.ts +137 -0
- package/src/server/rate-limit/postgres.ts +79 -0
- package/src/server/sharing/access.ts +29 -0
- package/src/server/sharing/actor.ts +12 -0
- package/src/server/sharing/capabilities/service.ts +262 -0
- package/src/server/sharing/continuation.ts +85 -0
- package/src/server/sharing/contracts.ts +80 -0
- package/src/server/sharing/crypto.ts +48 -0
- package/src/server/sharing/document-routes.ts +41 -0
- package/src/server/sharing/errors.ts +12 -0
- package/src/server/sharing/grants/service.ts +79 -0
- package/src/server/sharing/http.ts +41 -0
- package/src/server/sharing/index.ts +39 -0
- package/src/server/sharing/invitations/service.ts +315 -0
- package/src/server/sharing/policy.ts +44 -0
- package/src/server/sharing/routes.ts +251 -0
- package/src/server/sharing/service.ts +117 -0
- package/src/server/validation.ts +24 -0
- package/src/server/worker/interval.ts +23 -0
- package/src/server/worker/periodic.ts +42 -0
- package/src/server/workspaces/index.ts +16 -0
- package/src/server/workspaces/members.ts +502 -0
- package/src/server/workspaces/repository.ts +91 -0
- package/src/server/workspaces/routes.ts +198 -0
- package/src/server/workspaces/service.ts +84 -0
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CommitImageUploadsInput,
|
|
3
|
+
CommitUploadInput,
|
|
4
|
+
CreateDocumentInput,
|
|
5
|
+
CreateUploadInput,
|
|
6
|
+
DocumentDownload,
|
|
7
|
+
DocumentSummary,
|
|
8
|
+
ImageUploadOffer,
|
|
9
|
+
RequestImageUploadsInput,
|
|
10
|
+
SharedDocument
|
|
11
|
+
} from '#cloud/contract'
|
|
12
|
+
import { createUploadCleanupService } from '#cloud/server/cleanup'
|
|
13
|
+
import type { CloudDatabase } from '#cloud/server/db'
|
|
14
|
+
import {
|
|
15
|
+
canDeleteDocument,
|
|
16
|
+
canEditDocument,
|
|
17
|
+
resolveDocumentAccess
|
|
18
|
+
} from '#cloud/server/documents/access'
|
|
19
|
+
import {
|
|
20
|
+
DocumentConflictError,
|
|
21
|
+
DocumentForbiddenError,
|
|
22
|
+
DocumentNotFoundError,
|
|
23
|
+
UploadInvalidError
|
|
24
|
+
} from '#cloud/server/documents/errors'
|
|
25
|
+
import {
|
|
26
|
+
createDocumentImages,
|
|
27
|
+
currentImageUsage,
|
|
28
|
+
documentImageLinks,
|
|
29
|
+
revisionImageDownloads
|
|
30
|
+
} from '#cloud/server/documents/images'
|
|
31
|
+
import { writableDocument } from '#cloud/server/documents/limits'
|
|
32
|
+
import {
|
|
33
|
+
findDocument,
|
|
34
|
+
insertDocument,
|
|
35
|
+
listDocuments,
|
|
36
|
+
listSharedDocuments,
|
|
37
|
+
workspaceRole
|
|
38
|
+
} from '#cloud/server/documents/repository'
|
|
39
|
+
import { documentSummary, getDocumentSummaryRow } from '#cloud/server/documents/summary'
|
|
40
|
+
import type { CreateDocumentUploadResult } from '#cloud/server/documents/types'
|
|
41
|
+
import { announceVersions, recordCheckpoint } from '#cloud/server/documents/versions/checkpoint'
|
|
42
|
+
import type { ObjectStore, StoredObject } from '#cloud/server/objects'
|
|
43
|
+
import type { CloudPolicy } from '#cloud/server/policy/policy'
|
|
44
|
+
import { createStorageQuotaService } from '#cloud/server/quota'
|
|
45
|
+
import { isUndefined, limitAsync, omitBy, uniq, uniqBy } from 'es-toolkit'
|
|
46
|
+
import type { Kysely, Transaction } from 'kysely'
|
|
47
|
+
|
|
48
|
+
const DOWNLOAD_LIFETIME_MS = 5 * 60 * 1000
|
|
49
|
+
const UPLOAD_LIFETIME_MS = 15 * 60 * 1000
|
|
50
|
+
/** How many of a save's images are checked and landed at once. */
|
|
51
|
+
const IMAGE_COMMIT_CONCURRENCY = 8
|
|
52
|
+
const WRITABLE_ROLES = new Set(['admin', 'editor'])
|
|
53
|
+
|
|
54
|
+
export type DocumentServiceOptions = {
|
|
55
|
+
policy?: CloudPolicy
|
|
56
|
+
technicalMaximumUploadBytes?: number
|
|
57
|
+
/** Called once a save adds a checkpoint to the document's history. */
|
|
58
|
+
onVersionsChanged?: (documentId: string) => void
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Whether the stored object is the file the upload declared, which the commit names again. */
|
|
62
|
+
function matchesUpload(
|
|
63
|
+
stored: { checksum: string; byteSize: number; contentType: string },
|
|
64
|
+
upload: { checksum: string; byteSize: number | string | bigint; contentType: string }
|
|
65
|
+
): boolean {
|
|
66
|
+
return (
|
|
67
|
+
stored.checksum === upload.checksum &&
|
|
68
|
+
stored.byteSize === Number(upload.byteSize) &&
|
|
69
|
+
stored.contentType === upload.contentType
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function createDocumentService(
|
|
74
|
+
database: Kysely<CloudDatabase>,
|
|
75
|
+
objects: ObjectStore,
|
|
76
|
+
options: DocumentServiceOptions = {}
|
|
77
|
+
) {
|
|
78
|
+
const cleanup = createUploadCleanupService(database, objects)
|
|
79
|
+
const quota = createStorageQuotaService(database)
|
|
80
|
+
const images = createDocumentImages(database, objects, quota)
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Makes a committed upload the document's current revision, unless it already was, and records
|
|
84
|
+
* the checkpoint the save adds, if any. Whether the history gained one.
|
|
85
|
+
*/
|
|
86
|
+
async function landRevision(
|
|
87
|
+
transaction: Transaction<CloudDatabase>,
|
|
88
|
+
{
|
|
89
|
+
userId,
|
|
90
|
+
uploadId,
|
|
91
|
+
upload,
|
|
92
|
+
stored,
|
|
93
|
+
revisionId,
|
|
94
|
+
storageObjectId,
|
|
95
|
+
images: revisionImages,
|
|
96
|
+
name,
|
|
97
|
+
kind
|
|
98
|
+
}: {
|
|
99
|
+
userId: string
|
|
100
|
+
uploadId: string
|
|
101
|
+
upload: {
|
|
102
|
+
documentId: string
|
|
103
|
+
workspaceId: string
|
|
104
|
+
baseRevisionId: string | null
|
|
105
|
+
objectKey: string
|
|
106
|
+
}
|
|
107
|
+
stored: { checksum: string; byteSize: number; contentType: string }
|
|
108
|
+
revisionId: string
|
|
109
|
+
storageObjectId: string
|
|
110
|
+
images: CommitUploadInput['images']
|
|
111
|
+
name: CommitUploadInput['name']
|
|
112
|
+
kind: CommitUploadInput['kind']
|
|
113
|
+
}
|
|
114
|
+
): Promise<boolean> {
|
|
115
|
+
const lockedUpload = await transaction
|
|
116
|
+
.selectFrom('upload')
|
|
117
|
+
.select('status')
|
|
118
|
+
.where('id', '=', uploadId)
|
|
119
|
+
.forUpdate()
|
|
120
|
+
.executeTakeFirstOrThrow()
|
|
121
|
+
if (lockedUpload.status === 'committed') return false
|
|
122
|
+
if (lockedUpload.status !== 'finalizing') throw new UploadInvalidError()
|
|
123
|
+
const document = await transaction
|
|
124
|
+
.selectFrom('document')
|
|
125
|
+
.select(['currentRevisionId'])
|
|
126
|
+
.where('id', '=', upload.documentId)
|
|
127
|
+
.forUpdate()
|
|
128
|
+
.executeTakeFirstOrThrow()
|
|
129
|
+
if (document.currentRevisionId !== upload.baseRevisionId) {
|
|
130
|
+
throw new DocumentConflictError()
|
|
131
|
+
}
|
|
132
|
+
await transaction
|
|
133
|
+
.insertInto('storageObject')
|
|
134
|
+
.values({
|
|
135
|
+
id: storageObjectId,
|
|
136
|
+
objectKey: upload.objectKey,
|
|
137
|
+
checksum: stored.checksum,
|
|
138
|
+
byteSize: stored.byteSize,
|
|
139
|
+
contentType: stored.contentType
|
|
140
|
+
})
|
|
141
|
+
.execute()
|
|
142
|
+
await transaction
|
|
143
|
+
.insertInto('documentRevision')
|
|
144
|
+
.values({
|
|
145
|
+
id: revisionId,
|
|
146
|
+
documentId: upload.documentId,
|
|
147
|
+
parentRevisionId: upload.baseRevisionId,
|
|
148
|
+
storageObjectId,
|
|
149
|
+
createdBy: userId
|
|
150
|
+
})
|
|
151
|
+
.execute()
|
|
152
|
+
const attached = await images.attachInTransaction(transaction, {
|
|
153
|
+
workspaceId: upload.workspaceId,
|
|
154
|
+
revisionId,
|
|
155
|
+
images: revisionImages
|
|
156
|
+
})
|
|
157
|
+
if (!attached) throw new UploadInvalidError()
|
|
158
|
+
await transaction
|
|
159
|
+
.updateTable('document')
|
|
160
|
+
.set({
|
|
161
|
+
// A revision may also retitle its document, or say the file it holds is a board.
|
|
162
|
+
...omitBy({ name, kind }, isUndefined),
|
|
163
|
+
currentRevisionId: revisionId,
|
|
164
|
+
version: (expression) => expression('version', '+', 1)
|
|
165
|
+
})
|
|
166
|
+
.where('id', '=', upload.documentId)
|
|
167
|
+
.execute()
|
|
168
|
+
const checkpointed = await recordCheckpoint(transaction, {
|
|
169
|
+
documentId: upload.documentId,
|
|
170
|
+
previousRevisionId: document.currentRevisionId,
|
|
171
|
+
revisionId,
|
|
172
|
+
userId,
|
|
173
|
+
now: new Date()
|
|
174
|
+
})
|
|
175
|
+
await transaction
|
|
176
|
+
.updateTable('upload')
|
|
177
|
+
.set({ status: 'committed', finalizationStartedAt: null })
|
|
178
|
+
.where('id', '=', uploadId)
|
|
179
|
+
.execute()
|
|
180
|
+
await quota.commitInTransaction(transaction, uploadId)
|
|
181
|
+
return checkpointed
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Links for images a live room names, by checksum. */
|
|
185
|
+
async function imageLinksOf(documentId: string, checksums: string[]) {
|
|
186
|
+
const expiresAt = new Date(Date.now() + DOWNLOAD_LIFETIME_MS)
|
|
187
|
+
return {
|
|
188
|
+
images: await documentImageLinks(database, objects, { documentId, checksums, expiresAt })
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async function createDownload(documentId: string): Promise<DocumentDownload> {
|
|
193
|
+
const row = await getDocumentSummaryRow(database, documentId)
|
|
194
|
+
if (!row?.currentRevisionId) throw new DocumentNotFoundError()
|
|
195
|
+
const document: DocumentSummary = documentSummary(row)
|
|
196
|
+
const revision = await database
|
|
197
|
+
.selectFrom('documentRevision')
|
|
198
|
+
.innerJoin('storageObject', 'storageObject.id', 'documentRevision.storageObjectId')
|
|
199
|
+
.select([
|
|
200
|
+
'documentRevision.id as revisionId',
|
|
201
|
+
'storageObject.objectKey',
|
|
202
|
+
'storageObject.byteSize',
|
|
203
|
+
'storageObject.checksum',
|
|
204
|
+
'storageObject.contentType'
|
|
205
|
+
])
|
|
206
|
+
.where('documentRevision.id', '=', document.currentRevisionId)
|
|
207
|
+
.where('documentRevision.documentId', '=', documentId)
|
|
208
|
+
.executeTakeFirst()
|
|
209
|
+
if (!revision) throw new DocumentNotFoundError()
|
|
210
|
+
const expiresAt = new Date(Date.now() + DOWNLOAD_LIFETIME_MS)
|
|
211
|
+
return {
|
|
212
|
+
document,
|
|
213
|
+
revisionId: revision.revisionId,
|
|
214
|
+
byteSize: Number(revision.byteSize),
|
|
215
|
+
checksum: revision.checksum,
|
|
216
|
+
contentType: revision.contentType,
|
|
217
|
+
download: await objects.createDownload({ key: revision.objectKey, expiresAt }),
|
|
218
|
+
images: await revisionImageDownloads(database, objects, revision.revisionId, expiresAt)
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** What committing an upload reads of it and its document. */
|
|
223
|
+
function selectUploads() {
|
|
224
|
+
return database
|
|
225
|
+
.selectFrom('upload')
|
|
226
|
+
.innerJoin('document', 'document.id', 'upload.documentId')
|
|
227
|
+
.select([
|
|
228
|
+
'upload.id',
|
|
229
|
+
'upload.documentId',
|
|
230
|
+
'upload.kind',
|
|
231
|
+
'document.workspaceId',
|
|
232
|
+
'upload.baseRevisionId',
|
|
233
|
+
'upload.objectKey',
|
|
234
|
+
'upload.checksum',
|
|
235
|
+
'upload.byteSize',
|
|
236
|
+
'upload.contentType',
|
|
237
|
+
'upload.multipartUploadId',
|
|
238
|
+
'upload.status',
|
|
239
|
+
'upload.expiresAt'
|
|
240
|
+
])
|
|
241
|
+
}
|
|
242
|
+
type UploadRow = Awaited<ReturnType<ReturnType<typeof selectUploads>['executeTakeFirstOrThrow']>>
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Claims a pending upload, completes it when it came in parts, checks the store holds the file
|
|
246
|
+
* it declared, and lands it with `land`. An upload that fails goes back to pending, so its
|
|
247
|
+
* commit can be tried again.
|
|
248
|
+
*/
|
|
249
|
+
async function finalizeUpload<T>(
|
|
250
|
+
upload: UploadRow,
|
|
251
|
+
multipart: CommitUploadInput['multipart'],
|
|
252
|
+
land: (stored: StoredObject) => Promise<T>
|
|
253
|
+
): Promise<T> {
|
|
254
|
+
if (upload.status !== 'pending' || new Date(upload.expiresAt).getTime() <= Date.now()) {
|
|
255
|
+
throw new UploadInvalidError()
|
|
256
|
+
}
|
|
257
|
+
const claimed = await database
|
|
258
|
+
.updateTable('upload')
|
|
259
|
+
.set({ status: 'finalizing', finalizationStartedAt: new Date() })
|
|
260
|
+
.where('id', '=', upload.id)
|
|
261
|
+
.where('status', '=', 'pending')
|
|
262
|
+
.returning('id')
|
|
263
|
+
.executeTakeFirst()
|
|
264
|
+
if (!claimed) throw new UploadInvalidError()
|
|
265
|
+
try {
|
|
266
|
+
if (multipart) {
|
|
267
|
+
if (
|
|
268
|
+
!objects.capabilities.multipartUpload ||
|
|
269
|
+
multipart.uploadId !== upload.multipartUploadId
|
|
270
|
+
) {
|
|
271
|
+
throw new UploadInvalidError()
|
|
272
|
+
}
|
|
273
|
+
await objects.completeUpload({
|
|
274
|
+
key: upload.objectKey,
|
|
275
|
+
uploadId: multipart.uploadId,
|
|
276
|
+
parts: multipart.parts
|
|
277
|
+
})
|
|
278
|
+
}
|
|
279
|
+
const stored = await objects.head(upload.objectKey)
|
|
280
|
+
if (!stored || !matchesUpload(stored, upload)) throw new UploadInvalidError()
|
|
281
|
+
return await land(stored)
|
|
282
|
+
} catch (error) {
|
|
283
|
+
await database
|
|
284
|
+
.updateTable('upload')
|
|
285
|
+
.set({ status: 'pending', finalizationStartedAt: null })
|
|
286
|
+
.where('id', '=', upload.id)
|
|
287
|
+
.where('status', '=', 'finalizing')
|
|
288
|
+
.execute()
|
|
289
|
+
throw error
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function landImage(upload: UploadRow, stored: StoredObject): Promise<void> {
|
|
294
|
+
return database.transaction().execute((transaction) =>
|
|
295
|
+
images.landInTransaction(transaction, {
|
|
296
|
+
uploadId: upload.id,
|
|
297
|
+
workspaceId: upload.workspaceId,
|
|
298
|
+
objectKey: upload.objectKey,
|
|
299
|
+
stored
|
|
300
|
+
})
|
|
301
|
+
)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
async function commitUpload(
|
|
305
|
+
userId: string,
|
|
306
|
+
uploadId: string,
|
|
307
|
+
input: CommitUploadInput
|
|
308
|
+
): Promise<DocumentSummary> {
|
|
309
|
+
const upload = await selectUploads()
|
|
310
|
+
.where('upload.id', '=', uploadId)
|
|
311
|
+
.where('upload.createdBy', '=', userId)
|
|
312
|
+
.executeTakeFirst()
|
|
313
|
+
if (!upload) throw new DocumentNotFoundError()
|
|
314
|
+
const access = await resolveDocumentAccess(database, userId, upload.documentId)
|
|
315
|
+
if (!access) throw new DocumentNotFoundError()
|
|
316
|
+
if (!canEditDocument(access)) throw new DocumentForbiddenError()
|
|
317
|
+
if (input.checksum !== upload.checksum) throw new UploadInvalidError()
|
|
318
|
+
if (upload.status !== 'committed') {
|
|
319
|
+
const checkpointed =
|
|
320
|
+
upload.kind === 'image'
|
|
321
|
+
? await finalizeUpload(upload, input.multipart, (stored) =>
|
|
322
|
+
landImage(upload, stored).then(() => false)
|
|
323
|
+
)
|
|
324
|
+
: await finalizeUpload(upload, input.multipart, (stored) =>
|
|
325
|
+
database.transaction().execute((transaction) =>
|
|
326
|
+
landRevision(transaction, {
|
|
327
|
+
userId,
|
|
328
|
+
uploadId,
|
|
329
|
+
upload,
|
|
330
|
+
stored,
|
|
331
|
+
revisionId: crypto.randomUUID(),
|
|
332
|
+
storageObjectId: crypto.randomUUID(),
|
|
333
|
+
images: input.images,
|
|
334
|
+
name: input.name,
|
|
335
|
+
kind: input.kind
|
|
336
|
+
})
|
|
337
|
+
)
|
|
338
|
+
)
|
|
339
|
+
if (checkpointed) announceVersions(options.onVersionsChanged, upload.documentId)
|
|
340
|
+
}
|
|
341
|
+
const document = await findDocument(database, userId, upload.documentId)
|
|
342
|
+
if (!document) throw new DocumentNotFoundError()
|
|
343
|
+
return document
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return {
|
|
347
|
+
async cleanupExpiredUploads(now = new Date()): Promise<number> {
|
|
348
|
+
const result = await cleanup.cleanupExpiredUploads({
|
|
349
|
+
batchSize: 100,
|
|
350
|
+
leaseDurationMs: 5 * 60 * 1000,
|
|
351
|
+
now
|
|
352
|
+
})
|
|
353
|
+
if (result.failed > 0) throw new Error('One or more expired uploads could not be cleaned')
|
|
354
|
+
return result.cleaned
|
|
355
|
+
},
|
|
356
|
+
|
|
357
|
+
list(userId: string, workspaceId: string): Promise<DocumentSummary[] | undefined> {
|
|
358
|
+
return listDocuments(database, userId, workspaceId)
|
|
359
|
+
},
|
|
360
|
+
|
|
361
|
+
listShared(userId: string): Promise<SharedDocument[]> {
|
|
362
|
+
return listSharedDocuments(database, userId)
|
|
363
|
+
},
|
|
364
|
+
|
|
365
|
+
async usage(userId: string, workspaceId: string) {
|
|
366
|
+
const role = await workspaceRole(database, userId, workspaceId)
|
|
367
|
+
if (!role) throw new DocumentNotFoundError()
|
|
368
|
+
const result = await database
|
|
369
|
+
.selectFrom('document')
|
|
370
|
+
.leftJoin('documentRevision', 'documentRevision.id', 'document.currentRevisionId')
|
|
371
|
+
.leftJoin('storageObject', 'storageObject.id', 'documentRevision.storageObjectId')
|
|
372
|
+
.select((expression) => [
|
|
373
|
+
expression.fn.count('document.id').as('documentCount'),
|
|
374
|
+
expression.fn.count('storageObject.id').as('objectCount'),
|
|
375
|
+
expression.fn
|
|
376
|
+
.coalesce(expression.fn.sum('storageObject.byteSize'), expression.val(0))
|
|
377
|
+
.as('bytesUsed')
|
|
378
|
+
])
|
|
379
|
+
.where('document.workspaceId', '=', workspaceId)
|
|
380
|
+
.where('document.deletedAt', 'is', null)
|
|
381
|
+
.executeTakeFirstOrThrow()
|
|
382
|
+
const shared = await currentImageUsage(database, workspaceId)
|
|
383
|
+
return {
|
|
384
|
+
bytesUsed: Number(result.bytesUsed) + shared.bytesUsed,
|
|
385
|
+
objectCount: Number(result.objectCount) + shared.objectCount,
|
|
386
|
+
documentCount: Number(result.documentCount)
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
|
|
390
|
+
async access(userId: string, documentId: string) {
|
|
391
|
+
const access = await resolveDocumentAccess(database, userId, documentId)
|
|
392
|
+
if (!access) throw new DocumentNotFoundError()
|
|
393
|
+
return access
|
|
394
|
+
},
|
|
395
|
+
|
|
396
|
+
async downloadShared(documentId: string): Promise<DocumentDownload> {
|
|
397
|
+
return createDownload(documentId)
|
|
398
|
+
},
|
|
399
|
+
|
|
400
|
+
/** Links for images a live room names, for someone who may view the document. */
|
|
401
|
+
async imageLinks(userId: string, documentId: string, checksums: string[]) {
|
|
402
|
+
const access = await resolveDocumentAccess(database, userId, documentId)
|
|
403
|
+
if (!access) throw new DocumentNotFoundError()
|
|
404
|
+
return imageLinksOf(documentId, checksums)
|
|
405
|
+
},
|
|
406
|
+
|
|
407
|
+
/** Links for images a live room names, for a guest a share already let in. */
|
|
408
|
+
imageLinksShared(documentId: string, checksums: string[]) {
|
|
409
|
+
return imageLinksOf(documentId, checksums)
|
|
410
|
+
},
|
|
411
|
+
|
|
412
|
+
async download(userId: string, documentId: string): Promise<DocumentDownload> {
|
|
413
|
+
const access = await resolveDocumentAccess(database, userId, documentId)
|
|
414
|
+
if (!access) throw new DocumentNotFoundError()
|
|
415
|
+
return createDownload(documentId)
|
|
416
|
+
},
|
|
417
|
+
|
|
418
|
+
async remove(userId: string, documentId: string): Promise<void> {
|
|
419
|
+
const access = await resolveDocumentAccess(database, userId, documentId)
|
|
420
|
+
if (!access) throw new DocumentNotFoundError()
|
|
421
|
+
if (!canEditDocument(access) || !(await canDeleteDocument(database, userId, documentId))) {
|
|
422
|
+
throw new DocumentForbiddenError()
|
|
423
|
+
}
|
|
424
|
+
await database
|
|
425
|
+
.updateTable('document')
|
|
426
|
+
.set({ deletedAt: new Date() })
|
|
427
|
+
.where('id', '=', documentId)
|
|
428
|
+
.where('deletedAt', 'is', null)
|
|
429
|
+
.execute()
|
|
430
|
+
},
|
|
431
|
+
|
|
432
|
+
async create(
|
|
433
|
+
userId: string,
|
|
434
|
+
workspaceId: string,
|
|
435
|
+
input: CreateDocumentInput
|
|
436
|
+
): Promise<DocumentSummary> {
|
|
437
|
+
const role = await workspaceRole(database, userId, workspaceId)
|
|
438
|
+
if (!role) throw new DocumentNotFoundError()
|
|
439
|
+
if (!WRITABLE_ROLES.has(role)) throw new DocumentForbiddenError()
|
|
440
|
+
const documentId = input.id ?? crypto.randomUUID()
|
|
441
|
+
await insertDocument(database, {
|
|
442
|
+
id: documentId,
|
|
443
|
+
workspaceId,
|
|
444
|
+
name: input.name,
|
|
445
|
+
kind: input.kind,
|
|
446
|
+
createdBy: userId
|
|
447
|
+
})
|
|
448
|
+
const document = await findDocument(database, userId, documentId)
|
|
449
|
+
if (!document) throw new DocumentNotFoundError()
|
|
450
|
+
return document
|
|
451
|
+
},
|
|
452
|
+
|
|
453
|
+
async createUpload(
|
|
454
|
+
userId: string,
|
|
455
|
+
documentId: string,
|
|
456
|
+
input: CreateUploadInput
|
|
457
|
+
): Promise<CreateDocumentUploadResult> {
|
|
458
|
+
const { document, maximumFileBytes, maximumStorageBytes } = await writableDocument(
|
|
459
|
+
database,
|
|
460
|
+
options,
|
|
461
|
+
userId,
|
|
462
|
+
documentId
|
|
463
|
+
)
|
|
464
|
+
if (document.currentRevisionId !== input.baseRevisionId) throw new DocumentConflictError()
|
|
465
|
+
if (input.byteSize > maximumFileBytes) throw new UploadInvalidError()
|
|
466
|
+
const uploadId = crypto.randomUUID()
|
|
467
|
+
const objectKey = `documents/${document.workspaceId}/${documentId}/uploads/${uploadId}.fig`
|
|
468
|
+
const expiresAt = new Date(Date.now() + UPLOAD_LIFETIME_MS)
|
|
469
|
+
await database.transaction().execute(async (transaction) => {
|
|
470
|
+
await transaction
|
|
471
|
+
.insertInto('upload')
|
|
472
|
+
.values({
|
|
473
|
+
id: uploadId,
|
|
474
|
+
documentId,
|
|
475
|
+
baseRevisionId: input.baseRevisionId,
|
|
476
|
+
objectKey,
|
|
477
|
+
checksum: input.checksum,
|
|
478
|
+
byteSize: input.byteSize,
|
|
479
|
+
contentType: input.contentType,
|
|
480
|
+
multipartUploadId: null,
|
|
481
|
+
status: 'pending',
|
|
482
|
+
finalizationStartedAt: null,
|
|
483
|
+
createdBy: userId,
|
|
484
|
+
expiresAt
|
|
485
|
+
})
|
|
486
|
+
.execute()
|
|
487
|
+
await quota.reserveInTransaction(transaction, {
|
|
488
|
+
workspaceId: document.workspaceId,
|
|
489
|
+
uploadId,
|
|
490
|
+
bytes: input.byteSize,
|
|
491
|
+
expiresAt,
|
|
492
|
+
maximumBytes: maximumStorageBytes
|
|
493
|
+
})
|
|
494
|
+
})
|
|
495
|
+
let objectUpload
|
|
496
|
+
try {
|
|
497
|
+
objectUpload = await objects.createUpload({
|
|
498
|
+
key: objectKey,
|
|
499
|
+
byteSize: input.byteSize,
|
|
500
|
+
checksum: input.checksum,
|
|
501
|
+
contentType: input.contentType,
|
|
502
|
+
expiresAt
|
|
503
|
+
})
|
|
504
|
+
} catch (error) {
|
|
505
|
+
await quota.release(uploadId)
|
|
506
|
+
await database
|
|
507
|
+
.updateTable('upload')
|
|
508
|
+
.set({ status: 'abandoned' })
|
|
509
|
+
.where('id', '=', uploadId)
|
|
510
|
+
.execute()
|
|
511
|
+
throw error
|
|
512
|
+
}
|
|
513
|
+
if (objectUpload.kind === 'multipart') {
|
|
514
|
+
await database
|
|
515
|
+
.updateTable('upload')
|
|
516
|
+
.set({ multipartUploadId: objectUpload.uploadId })
|
|
517
|
+
.where('id', '=', uploadId)
|
|
518
|
+
.execute()
|
|
519
|
+
}
|
|
520
|
+
return { id: uploadId, upload: objectUpload }
|
|
521
|
+
},
|
|
522
|
+
|
|
523
|
+
/** Uploads for the images a save of the document will name that its workspace lacks. */
|
|
524
|
+
async requestImageUploads(
|
|
525
|
+
userId: string,
|
|
526
|
+
documentId: string,
|
|
527
|
+
input: RequestImageUploadsInput
|
|
528
|
+
): Promise<{ uploads: ImageUploadOffer[] }> {
|
|
529
|
+
const { document, maximumFileBytes, maximumStorageBytes } = await writableDocument(
|
|
530
|
+
database,
|
|
531
|
+
options,
|
|
532
|
+
userId,
|
|
533
|
+
documentId
|
|
534
|
+
)
|
|
535
|
+
if (input.images.some((image) => image.byteSize > maximumFileBytes)) {
|
|
536
|
+
throw new UploadInvalidError()
|
|
537
|
+
}
|
|
538
|
+
return {
|
|
539
|
+
uploads: await images.requestUploads({
|
|
540
|
+
userId,
|
|
541
|
+
documentId,
|
|
542
|
+
workspaceId: document.workspaceId,
|
|
543
|
+
images: input.images,
|
|
544
|
+
expiresAt: new Date(Date.now() + UPLOAD_LIFETIME_MS),
|
|
545
|
+
maximumBytes: maximumStorageBytes
|
|
546
|
+
})
|
|
547
|
+
}
|
|
548
|
+
},
|
|
549
|
+
commitUpload,
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Commits the image uploads a save asked for in one request, however many there are: each
|
|
553
|
+
* must be an image upload this person made for the document.
|
|
554
|
+
*/
|
|
555
|
+
async commitImageUploads(
|
|
556
|
+
userId: string,
|
|
557
|
+
documentId: string,
|
|
558
|
+
uploads: CommitImageUploadsInput['uploads']
|
|
559
|
+
): Promise<void> {
|
|
560
|
+
const access = await resolveDocumentAccess(database, userId, documentId)
|
|
561
|
+
if (!access) throw new DocumentNotFoundError()
|
|
562
|
+
if (!canEditDocument(access)) throw new DocumentForbiddenError()
|
|
563
|
+
const ids = uniq(uploads.map((upload) => upload.uploadId))
|
|
564
|
+
const rows = new Map(
|
|
565
|
+
(
|
|
566
|
+
await selectUploads()
|
|
567
|
+
.where('upload.id', 'in', ids)
|
|
568
|
+
.where('upload.documentId', '=', documentId)
|
|
569
|
+
.where('upload.createdBy', '=', userId)
|
|
570
|
+
.execute()
|
|
571
|
+
).map((row) => [row.id, row])
|
|
572
|
+
)
|
|
573
|
+
if (rows.size !== ids.length || [...rows.values()].some((row) => row.kind !== 'image')) {
|
|
574
|
+
throw new UploadInvalidError()
|
|
575
|
+
}
|
|
576
|
+
for (const commit of uploads) {
|
|
577
|
+
if (rows.get(commit.uploadId)?.checksum !== commit.checksum) throw new UploadInvalidError()
|
|
578
|
+
}
|
|
579
|
+
// Each image is its own object, so a few are checked and landed at once, each once however
|
|
580
|
+
// often the request names it.
|
|
581
|
+
const land = limitAsync(
|
|
582
|
+
(upload: UploadRow, multipart: CommitUploadInput['multipart']) =>
|
|
583
|
+
finalizeUpload(upload, multipart, (stored) => landImage(upload, stored)),
|
|
584
|
+
IMAGE_COMMIT_CONCURRENCY
|
|
585
|
+
)
|
|
586
|
+
await Promise.all(
|
|
587
|
+
uniqBy(uploads, (commit) => commit.uploadId).map(async (commit) => {
|
|
588
|
+
const upload = rows.get(commit.uploadId)
|
|
589
|
+
if (!upload) throw new UploadInvalidError()
|
|
590
|
+
if (upload.status !== 'committed') await land(upload, commit.multipart)
|
|
591
|
+
})
|
|
592
|
+
)
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
export type DocumentService = ReturnType<typeof createDocumentService>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { DocumentSummary } from '#cloud/contract'
|
|
2
|
+
import type { DocumentDatabase, DocumentSummaryRow } from '#cloud/server/documents/repository'
|
|
3
|
+
|
|
4
|
+
const SUMMARY_COLUMNS = [
|
|
5
|
+
'id',
|
|
6
|
+
'workspaceId',
|
|
7
|
+
'name',
|
|
8
|
+
'kind',
|
|
9
|
+
'currentRevisionId',
|
|
10
|
+
'version',
|
|
11
|
+
'createdAt',
|
|
12
|
+
'updatedAt'
|
|
13
|
+
] as const
|
|
14
|
+
|
|
15
|
+
function toISOString(value: Date | string): string {
|
|
16
|
+
return value instanceof Date ? value.toISOString() : value
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function documentSummary(row: DocumentSummaryRow): DocumentSummary {
|
|
20
|
+
return {
|
|
21
|
+
...row,
|
|
22
|
+
createdAt: toISOString(row.createdAt),
|
|
23
|
+
updatedAt: toISOString(row.updatedAt)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function getDocumentSummaryRow(
|
|
28
|
+
database: DocumentDatabase,
|
|
29
|
+
documentId: string
|
|
30
|
+
): Promise<DocumentSummaryRow | undefined> {
|
|
31
|
+
return database
|
|
32
|
+
.selectFrom('document')
|
|
33
|
+
.select(SUMMARY_COLUMNS)
|
|
34
|
+
.where('id', '=', documentId)
|
|
35
|
+
.where('deletedAt', 'is', null)
|
|
36
|
+
.executeTakeFirst()
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ObjectUpload } from '#cloud/server/objects'
|
|
2
|
+
|
|
3
|
+
export type CreateDocumentRecord = {
|
|
4
|
+
id: string
|
|
5
|
+
workspaceId: string
|
|
6
|
+
name: string
|
|
7
|
+
kind: 'design' | 'board'
|
|
8
|
+
createdBy: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type CreateDocumentUploadResult = {
|
|
12
|
+
id: string
|
|
13
|
+
upload: ObjectUpload
|
|
14
|
+
}
|