@open-pencil/cloud 0.17.0-beta.4 → 0.17.0-beta.6
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/README.md +2 -1
- package/dist/bin/server.mjs +1 -1
- package/dist/bin/server.mjs.map +1 -1
- package/dist/bin/services.mjs +1 -1
- package/dist/bin/services.mjs.map +1 -1
- package/dist/client.d.ts +783 -47
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1651 -382
- package/dist/client.js.map +1 -1
- package/dist/contract.d.ts +2 -2
- package/dist/contract.js +2 -2
- package/dist/contract2.js +701 -45
- package/dist/contract2.js.map +1 -1
- package/dist/email.d.ts +2138 -34
- package/dist/email.d.ts.map +1 -1
- package/dist/email.js +4343 -306
- package/dist/email.js.map +1 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +61 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +1338 -44
- package/dist/index.d.ts.map +1 -1
- package/dist/index2.d.ts +45 -0
- package/dist/index2.d.ts.map +1 -0
- package/dist/listen.mjs +958 -340
- package/dist/listen.mjs.map +1 -1
- package/dist/runtime-cloudflare.d.ts +93 -0
- package/dist/runtime-cloudflare.d.ts.map +1 -0
- package/dist/runtime-cloudflare.js +18032 -0
- package/dist/runtime-cloudflare.js.map +1 -0
- package/dist/runtime-node.d.mts +12615 -5249
- package/dist/runtime-node.d.mts.map +1 -1
- package/dist/server.d.ts +17367 -8567
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +13587 -7333
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +11601 -5401
- package/dist/server.mjs.map +1 -1
- package/dist/server2.mjs +84 -62
- package/dist/server2.mjs.map +1 -1
- package/package.json +31 -5
- package/src/admin/api/routes.ts +263 -190
- package/src/admin/audit/service.ts +11 -3
- package/src/admin/bootstrap.ts +86 -0
- package/src/admin/documents/service.ts +195 -10
- package/src/admin/email/service.ts +2 -1
- package/src/admin/enrollment/email.ts +17 -3
- package/src/admin/enrollment/service.ts +71 -10
- package/src/admin/errors.ts +5 -0
- package/src/admin/index.ts +1 -0
- package/src/admin/reports/service.ts +15 -3
- package/src/admin/schema.ts +6 -5
- package/src/admin/users/service.ts +173 -16
- package/src/client/api.ts +52 -473
- package/src/client/auth/client.ts +22 -3
- package/src/client/comments.ts +205 -0
- package/src/client/community.ts +40 -0
- package/src/client/device-authorization.ts +4 -20
- package/src/client/discovery.ts +39 -11
- package/src/client/documents.ts +160 -0
- package/src/client/files/archive.ts +60 -0
- package/src/client/files/checksum.ts +7 -0
- package/src/client/files/download.ts +122 -0
- package/src/client/files/images.ts +89 -0
- package/src/client/files/index.ts +15 -0
- package/src/client/files/objects.ts +173 -0
- package/src/client/files/save.ts +79 -0
- package/src/client/index.ts +4 -0
- package/src/client/portal/account.ts +73 -3
- package/src/client/portal/administration.ts +52 -5
- package/src/client/portal/request.ts +6 -2
- package/src/client/response.ts +21 -0
- package/src/client/schema.ts +8 -0
- package/src/client/services.ts +23 -18
- package/src/client/sharing.ts +262 -0
- package/src/client/tour.ts +44 -0
- package/src/client/versions.ts +110 -0
- package/src/contract/account.ts +111 -11
- package/src/contract/admin/index.ts +48 -3
- package/src/contract/billing.ts +235 -0
- package/src/contract/collaboration.ts +5 -0
- package/src/contract/comments.ts +223 -0
- package/src/contract/community.ts +60 -0
- package/src/contract/discovery.ts +94 -5
- package/src/contract/entitlements.ts +10 -0
- package/src/contract/index.ts +64 -5
- package/src/contract/links.ts +62 -4
- package/src/contract/locale.ts +27 -0
- package/src/contract/portal.ts +12 -1
- package/src/contract/relay.ts +3 -1
- package/src/contract/routes.ts +10 -0
- package/src/contract/services.ts +62 -20
- package/src/contract/workspaces.ts +5 -0
- package/src/email/i18n.ts +174 -0
- package/src/email/index.ts +13 -2
- package/src/email/locales/ar.json +169 -0
- package/src/email/locales/de.json +169 -0
- package/src/email/locales/es.json +169 -0
- package/src/email/locales/fr.json +169 -0
- package/src/email/locales/it.json +169 -0
- package/src/email/locales/ja.json +169 -0
- package/src/email/locales/pl.json +169 -0
- package/src/email/locales/pt-br.json +169 -0
- package/src/email/locales/ru.json +169 -0
- package/src/email/locales/zh-cn.json +169 -0
- package/src/email/messages.ts +235 -0
- package/src/email/render.ts +160 -276
- package/src/email/samples.ts +142 -0
- package/src/email/schema.ts +98 -8
- package/src/email/templates/BrandEmail.vue +56 -0
- package/src/email/templates/CommentNotification.vue +39 -0
- package/src/email/templates/DocumentBlocked.vue +45 -0
- package/src/email/templates/DocumentInvitation.vue +24 -0
- package/src/email/templates/DocumentReport.vue +32 -0
- package/src/email/templates/DocumentReportDecided.vue +36 -0
- package/src/email/templates/DocumentReportReceived.vue +18 -0
- package/src/email/templates/DocumentRestored.vue +24 -0
- package/src/email/templates/EmailChangeRequested.vue +24 -0
- package/src/email/templates/EmailRoot.vue +19 -0
- package/src/email/templates/EmailText.vue +9 -0
- package/src/email/templates/EmailVerification.vue +38 -0
- package/src/email/templates/EnrollmentInvitation.vue +53 -0
- package/src/email/templates/EnrollmentNotification.vue +24 -0
- package/src/email/templates/EnrollmentUpdate.vue +52 -0
- package/src/email/templates/NewSignIn.vue +37 -0
- package/src/email/templates/PasswordChanged.vue +22 -0
- package/src/email/templates/PasswordReset.vue +23 -0
- package/src/email/templates/StorageLimitReached.vue +28 -0
- package/src/email/templates/TwoStepChanged.vue +47 -0
- package/src/email/templates/WaitlistConfirmation.vue +29 -0
- package/src/email/templates/WorkspaceInvitation.vue +28 -0
- package/src/email/templates/brand.ts +15 -61
- package/src/email/templates/localization.ts +17 -0
- package/src/errors/index.ts +6 -0
- package/src/{server/errors → errors}/posthog.ts +28 -4
- package/src/global.d.ts +7 -0
- package/src/runtime/cloudflare/email.ts +2 -0
- package/src/runtime/cloudflare/relay/index.ts +28 -7
- package/src/runtime/cloudflare/tsconfig.json +2 -1
- package/src/runtime/cloudflare/worker.ts +14 -1
- package/src/runtime/cloudflare/xml.ts +12 -0
- package/src/runtime/node/admin.ts +51 -47
- package/src/runtime/node/cleanup.ts +5 -1
- package/src/runtime/node/email/runtime.ts +1 -0
- package/src/runtime/node/email/transport.ts +14 -10
- package/src/runtime/node/main.ts +1 -1
- package/src/runtime/node/server.ts +20 -4
- package/src/runtime/node/services/main.ts +1 -1
- package/src/runtime/posthog/errors.ts +5 -2
- package/src/runtime/s3/objects.ts +17 -0
- package/src/runtime/site/community.ts +101 -0
- package/src/runtime/site/server.ts +17 -1
- package/src/server/account/actions.ts +3 -1
- package/src/server/account/deletion.ts +40 -4
- package/src/server/account/routes.ts +305 -253
- package/src/server/account/tokens.ts +57 -0
- package/src/server/api/router.ts +44 -6
- package/src/server/app/checks.ts +89 -0
- package/src/server/app/cors.ts +44 -0
- package/src/server/app/editors.ts +20 -0
- package/src/server/app/index.ts +128 -0
- package/src/server/app/indexing.ts +40 -0
- package/src/server/app/limiters.ts +53 -0
- package/src/server/app/routes.ts +123 -0
- package/src/server/app/services.ts +219 -0
- package/src/server/auth/access-control.ts +13 -8
- package/src/server/auth/access-tokens.ts +62 -0
- package/src/server/auth/account.ts +13 -12
- package/src/server/auth/activity.ts +7 -2
- package/src/server/auth/adapter.ts +36 -3
- package/src/server/auth/email.ts +33 -18
- package/src/server/auth/endpoints.ts +4 -0
- package/src/server/auth/enrollment.ts +116 -0
- package/src/server/auth/factory.ts +165 -189
- package/src/server/auth/index.ts +1 -1
- package/src/server/auth/logger.ts +23 -0
- package/src/server/auth/methods.ts +162 -0
- package/src/server/auth/mfa-assurance.ts +190 -2
- package/src/server/auth/passwords.ts +43 -0
- package/src/server/auth/rate-limit.ts +31 -0
- package/src/server/auth/runtime.ts +19 -5
- package/src/server/auth/session.ts +2 -0
- package/src/server/auth/social-providers.ts +70 -24
- package/src/server/billing/index.ts +8 -0
- package/src/server/billing/notify.ts +55 -0
- package/src/server/billing/routes.ts +27 -0
- package/src/server/billing/seats.ts +17 -0
- package/src/server/billing/tokens.ts +37 -0
- package/src/server/cleanup/configured.ts +16 -3
- package/src/server/cleanup/documents.ts +5 -2
- package/src/server/cleanup/revisions.ts +6 -3
- package/src/server/cleanup/uploads.ts +2 -1
- package/src/server/cleanup/worker.ts +10 -1
- package/src/server/collaboration/relay/connection.ts +7 -2
- package/src/server/collaboration/relay/hub.ts +80 -166
- package/src/server/collaboration/relay/room.ts +154 -0
- package/src/server/collaboration/routes.ts +8 -5
- package/src/server/collaboration/service.ts +21 -2
- package/src/server/comments/index.ts +9 -0
- package/src/server/comments/notify.ts +277 -0
- package/src/server/comments/routes.ts +352 -0
- package/src/server/comments/rows.ts +249 -0
- package/src/server/comments/service.ts +570 -0
- package/src/server/community/index.ts +2 -0
- package/src/server/community/routes.ts +93 -0
- package/src/server/community/service.ts +134 -0
- package/src/server/config/deployment.ts +35 -10
- package/src/server/config/index.ts +2 -2
- package/src/server/config/public.ts +25 -6
- package/src/server/config/schema.ts +53 -293
- package/src/server/config/toml/schema.ts +330 -0
- package/src/server/db/index.ts +3 -1
- package/src/server/db/migrate.ts +33 -1
- package/src/server/db/migrations/009_access_tokens.ts +47 -0
- package/src/server/db/migrations/010_storage_limit_notices.ts +50 -0
- package/src/server/db/migrations/011_account_ids.ts +30 -0
- package/src/server/db/migrations/012_email_locales.ts +34 -0
- package/src/server/db/migrations/013_document_block_emails.ts +40 -0
- package/src/server/db/migrations/014_report_replies.ts +28 -0
- package/src/server/db/migrations/015_comments.ts +57 -0
- package/src/server/db/migrations/016_comment_notifications.ts +76 -0
- package/src/server/db/migrations/017_invitation_emails.ts +19 -0
- package/src/server/db/migrations/018_enrollment_source.ts +17 -0
- package/src/server/db/migrations/schema.ts +26 -1
- package/src/server/db/tables.ts +122 -3
- package/src/server/db/users.ts +22 -0
- package/src/server/documents/access.ts +17 -0
- package/src/server/documents/images.ts +6 -1
- package/src/server/documents/index.ts +1 -1
- package/src/server/documents/limits.ts +7 -1
- package/src/server/documents/routes.ts +12 -12
- package/src/server/documents/service.ts +31 -407
- package/src/server/documents/summary.ts +15 -0
- package/src/server/documents/uploads.ts +450 -0
- package/src/server/documents/versions/routes.ts +7 -8
- package/src/server/documents/versions/service.ts +86 -26
- package/src/server/email/invitations.ts +1 -0
- package/src/server/email/service.ts +39 -6
- package/src/server/email/types.ts +13 -0
- package/src/server/errors/index.ts +49 -12
- package/src/server/index.ts +27 -6
- package/src/server/internal/routes.ts +8 -2
- package/src/server/internal/service.ts +10 -0
- package/src/server/invitations/budget.ts +3 -1
- package/src/server/invitations/index.ts +1 -0
- package/src/server/invitations/links.ts +6 -0
- package/src/server/invitations/types.ts +5 -1
- package/src/server/objects/types.ts +5 -0
- package/src/server/pictures/service.ts +3 -1
- package/src/server/policy/configured.ts +9 -3
- package/src/server/policy/database.ts +13 -2
- package/src/server/policy/policy.ts +39 -12
- package/src/server/policy/service.ts +71 -52
- package/src/server/policy/storage.ts +33 -0
- package/src/server/policy/workspace.ts +5 -2
- package/src/server/quota/index.ts +6 -0
- package/src/server/quota/notices.ts +121 -0
- package/src/server/quota/storage.ts +5 -0
- package/src/server/rate-limit/middleware.ts +4 -0
- package/src/server/reports/index.ts +1 -0
- package/src/server/reports/replies.ts +55 -0
- package/src/server/reports/routes.ts +5 -3
- package/src/server/reports/service.ts +27 -3
- package/src/server/services/routes.ts +2 -2
- package/src/server/sharing/capabilities/service.ts +3 -4
- package/src/server/sharing/document-routes.ts +3 -3
- package/src/server/sharing/invitations/service.ts +17 -8
- package/src/server/sharing/routes.ts +15 -15
- package/src/server/validation.ts +35 -24
- package/src/server/workspaces/members.ts +57 -31
- package/src/server/workspaces/repository.ts +23 -12
- package/src/server/workspaces/routes.ts +8 -8
- package/src/services/app.ts +31 -22
- package/src/services/config.ts +48 -8
- package/src/services/metering.ts +15 -27
- package/src/services/usage.ts +6 -14
- package/src/email/templates/document-invitation.ts +0 -35
- package/src/email/templates/enrollment.ts +0 -27
- package/src/email/templates/layout.ts +0 -18
- package/src/server/app.ts +0 -453
|
@@ -0,0 +1,570 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MAX_COMMENT_THREADS_PER_DOCUMENT,
|
|
3
|
+
MAX_COMMENTS_PER_THREAD,
|
|
4
|
+
type CloudCommentThread,
|
|
5
|
+
type CommentAccess,
|
|
6
|
+
type CommentThreads,
|
|
7
|
+
type CreateCommentInput,
|
|
8
|
+
type CreateCommentThreadInput,
|
|
9
|
+
type ImportCommentThreadsInput,
|
|
10
|
+
type NotificationSettings,
|
|
11
|
+
type UpdateCommentInput,
|
|
12
|
+
type UpdateCommentThreadInput
|
|
13
|
+
} from '#cloud/contract'
|
|
14
|
+
import type { CloudDatabase } from '#cloud/server/db'
|
|
15
|
+
import { resolveDocumentCommentAccess } from '#cloud/server/documents/access'
|
|
16
|
+
import { DocumentForbiddenError, DocumentNotFoundError } from '#cloud/server/documents/errors'
|
|
17
|
+
import { logCloud, loggedError } from '#cloud/server/logging'
|
|
18
|
+
import type { DocumentSharingService } from '#cloud/server/sharing'
|
|
19
|
+
import { chunk, groupBy, isEmptyObject } from 'es-toolkit'
|
|
20
|
+
import type { Kysely, Transaction } from 'kysely'
|
|
21
|
+
|
|
22
|
+
import {
|
|
23
|
+
commentPeople,
|
|
24
|
+
notifyComment,
|
|
25
|
+
recordMentions,
|
|
26
|
+
readNotificationSettings,
|
|
27
|
+
threadParticipants,
|
|
28
|
+
writeNotificationSettings,
|
|
29
|
+
type CommentNotifier
|
|
30
|
+
} from './notify'
|
|
31
|
+
import {
|
|
32
|
+
anchorValues,
|
|
33
|
+
comments,
|
|
34
|
+
documentThreadCount,
|
|
35
|
+
findThread,
|
|
36
|
+
lockDocument,
|
|
37
|
+
markRead,
|
|
38
|
+
readsOf,
|
|
39
|
+
resolutionChange,
|
|
40
|
+
threadOf,
|
|
41
|
+
threads,
|
|
42
|
+
type ThreadRow,
|
|
43
|
+
type Source
|
|
44
|
+
} from './rows'
|
|
45
|
+
|
|
46
|
+
/** A document holds as many threads, or a thread as many comments, as it may. */
|
|
47
|
+
export class CommentLimitError extends Error {
|
|
48
|
+
override readonly name = 'CommentLimitError'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A new thread or comment named an ID something else already has. */
|
|
52
|
+
export class CommentConflictError extends Error {
|
|
53
|
+
override readonly name = 'CommentConflictError'
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Whose request it is and what they may do, settled before any comment is touched: a member or
|
|
58
|
+
* grantee through `forMember`, or whoever follows a share link through `forShare`.
|
|
59
|
+
*/
|
|
60
|
+
export type CommentActor = Omit<CommentAccess, 'accountId'> & {
|
|
61
|
+
documentId: string
|
|
62
|
+
/** Null for a guest on a link, who may only read. */
|
|
63
|
+
userId: string | null
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** A request's input as callers may write it: naming nobody when it lists no mentions. */
|
|
67
|
+
type Mentioning<Input extends { mentions: string[] }> = Omit<Input, 'mentions'> & {
|
|
68
|
+
mentions?: readonly string[]
|
|
69
|
+
}
|
|
70
|
+
type NewThread = Mentioning<CreateCommentThreadInput>
|
|
71
|
+
type NewComment = Mentioning<CreateCommentInput>
|
|
72
|
+
type CommentEdit = Mentioning<UpdateCommentInput>
|
|
73
|
+
|
|
74
|
+
/** Rows one insert writes, within PostgreSQL's parameters per statement. */
|
|
75
|
+
const INSERT_BATCH = 500
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A thread's comment times as a file gave them, each after the one before, so the first one is
|
|
79
|
+
* the thread's first wherever the file wrote two at the same moment.
|
|
80
|
+
*/
|
|
81
|
+
function importedTimes(times: readonly string[]): Date[] {
|
|
82
|
+
const result: Date[] = []
|
|
83
|
+
for (const time of times) {
|
|
84
|
+
const at = new Date(time)
|
|
85
|
+
const previous = result.at(-1)
|
|
86
|
+
result.push(previous && at <= previous ? new Date(previous.getTime() + 1) : at)
|
|
87
|
+
}
|
|
88
|
+
return result
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function requireCommenter(actor: CommentActor): string {
|
|
92
|
+
if (!actor.canComment || actor.userId === null) throw new DocumentForbiddenError()
|
|
93
|
+
return actor.userId
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The comments of Cloud documents. Everyone who can read a document reads its comments; everyone
|
|
98
|
+
* signed in who can read writes them. A comment is changed only by its author, and deleted by its
|
|
99
|
+
* author or an editor; a thread's pin is moved by whoever started it or an editor, and anyone who
|
|
100
|
+
* comments resolves or reopens it. Deleting a thread's first comment deletes the thread.
|
|
101
|
+
*/
|
|
102
|
+
export function createCommentService(
|
|
103
|
+
database: Kysely<CloudDatabase>,
|
|
104
|
+
options: {
|
|
105
|
+
sharing?: Pick<DocumentSharingService, 'resolveShare'>
|
|
106
|
+
/** Called once a thread changes, so the document's live rooms fetch it again. */
|
|
107
|
+
onCommentsChanged?: (documentId: string, threadId: string) => void
|
|
108
|
+
/** Emails the people a comment concerns; without it nobody hears by email. */
|
|
109
|
+
notifier?: CommentNotifier
|
|
110
|
+
} = {}
|
|
111
|
+
) {
|
|
112
|
+
/**
|
|
113
|
+
* Records whom a comment names and emails them, and, for a reply, the thread's other writers
|
|
114
|
+
* who asked to hear about everything.
|
|
115
|
+
*/
|
|
116
|
+
async function tell(
|
|
117
|
+
transaction: Transaction<CloudDatabase>,
|
|
118
|
+
actor: CommentActor,
|
|
119
|
+
comment: { commentId: string; threadId: string; body: string },
|
|
120
|
+
mentions: readonly string[],
|
|
121
|
+
{ reply = false } = {}
|
|
122
|
+
) {
|
|
123
|
+
const authorId = requireCommenter(actor)
|
|
124
|
+
const mentioned = await recordMentions(transaction, {
|
|
125
|
+
documentId: actor.documentId,
|
|
126
|
+
commentId: comment.commentId,
|
|
127
|
+
authorId,
|
|
128
|
+
mentions
|
|
129
|
+
})
|
|
130
|
+
if (!options.notifier) return
|
|
131
|
+
const participants = reply
|
|
132
|
+
? await threadParticipants(transaction, actor.documentId, comment.threadId, authorId)
|
|
133
|
+
: []
|
|
134
|
+
await notifyComment(transaction, options.notifier, {
|
|
135
|
+
id: comment.commentId,
|
|
136
|
+
documentId: actor.documentId,
|
|
137
|
+
threadId: comment.threadId,
|
|
138
|
+
authorId,
|
|
139
|
+
body: comment.body,
|
|
140
|
+
mentioned,
|
|
141
|
+
participants
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function announce(documentId: string, threadId: string): void {
|
|
146
|
+
try {
|
|
147
|
+
options.onCommentsChanged?.(documentId, threadId)
|
|
148
|
+
} catch (error) {
|
|
149
|
+
logCloud('error', 'Announcing a comment change failed', { error: loggedError(error) })
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async function readThread(
|
|
154
|
+
source: Source,
|
|
155
|
+
row: ThreadRow,
|
|
156
|
+
viewer: string | null
|
|
157
|
+
): Promise<CloudCommentThread> {
|
|
158
|
+
const reads = await readsOf(source, viewer, [row.id])
|
|
159
|
+
return threadOf(row, await comments(source, [row.id]), viewer, reads.get(row.id))
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Marks the thread changed now, and read by whoever changed it, and answers it as it is after
|
|
164
|
+
* the change.
|
|
165
|
+
*/
|
|
166
|
+
async function touched(
|
|
167
|
+
transaction: Transaction<CloudDatabase>,
|
|
168
|
+
actor: CommentActor,
|
|
169
|
+
threadId: string
|
|
170
|
+
): Promise<CloudCommentThread> {
|
|
171
|
+
await transaction
|
|
172
|
+
.updateTable('commentThread')
|
|
173
|
+
.set({ updatedAt: new Date() })
|
|
174
|
+
.where('id', '=', threadId)
|
|
175
|
+
.execute()
|
|
176
|
+
if (actor.userId !== null) await markRead(transaction, actor.userId, threadId)
|
|
177
|
+
return readThread(
|
|
178
|
+
transaction,
|
|
179
|
+
await findThread(transaction, actor.documentId, threadId),
|
|
180
|
+
actor.userId
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async function findComment(
|
|
185
|
+
source: Source,
|
|
186
|
+
threadId: string,
|
|
187
|
+
commentId: string
|
|
188
|
+
): Promise<{ authorId: string | null; first: boolean }> {
|
|
189
|
+
const rows = await source
|
|
190
|
+
.selectFrom('comment')
|
|
191
|
+
.select(['id', 'authorId'])
|
|
192
|
+
.where('threadId', '=', threadId)
|
|
193
|
+
.orderBy('createdAt')
|
|
194
|
+
.orderBy('id')
|
|
195
|
+
.execute()
|
|
196
|
+
const index = rows.findIndex((comment) => comment.id === commentId)
|
|
197
|
+
const found = rows[index]
|
|
198
|
+
if (!found) throw new DocumentNotFoundError()
|
|
199
|
+
return { authorId: found.authorId, first: index === 0 }
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** A comment of a thread, with the thread held until the transaction ends. */
|
|
203
|
+
async function lockedComment(
|
|
204
|
+
transaction: Transaction<CloudDatabase>,
|
|
205
|
+
actor: CommentActor,
|
|
206
|
+
threadId: string,
|
|
207
|
+
commentId: string
|
|
208
|
+
) {
|
|
209
|
+
await findThread(transaction, actor.documentId, threadId, true)
|
|
210
|
+
return findComment(transaction, threadId, commentId)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** Every thread on the document, oldest first, with what the asker may do. */
|
|
214
|
+
async function list(actor: CommentActor): Promise<CommentThreads> {
|
|
215
|
+
const rows = await threads(database)
|
|
216
|
+
.where('commentThread.documentId', '=', actor.documentId)
|
|
217
|
+
.orderBy('commentThread.createdAt')
|
|
218
|
+
.orderBy('commentThread.id')
|
|
219
|
+
.execute()
|
|
220
|
+
const ids = rows.map((row) => row.id)
|
|
221
|
+
const byThread =
|
|
222
|
+
rows.length > 0 ? groupBy(await comments(database, ids), (c) => c.threadId) : {}
|
|
223
|
+
const reads = await readsOf(database, actor.userId, ids)
|
|
224
|
+
return {
|
|
225
|
+
threads: rows.map((row) =>
|
|
226
|
+
threadOf(row, byThread[row.id] ?? [], actor.userId, reads.get(row.id))
|
|
227
|
+
),
|
|
228
|
+
access: {
|
|
229
|
+
canComment: actor.canComment,
|
|
230
|
+
canModerate: actor.canModerate,
|
|
231
|
+
accountId: actor.userId
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return {
|
|
237
|
+
/** A member's or grantee's access to a document's comments. */
|
|
238
|
+
async forMember(userId: string, documentId: string): Promise<CommentActor> {
|
|
239
|
+
const access = await resolveDocumentCommentAccess(database, userId, documentId)
|
|
240
|
+
if (!access) throw new DocumentNotFoundError()
|
|
241
|
+
return { ...access, documentId, userId }
|
|
242
|
+
},
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Access through a share link: everyone with it reads; people signed in also comment, and
|
|
246
|
+
* moderate when the link lets them edit. A guest on any link only reads.
|
|
247
|
+
*/
|
|
248
|
+
async forShare(
|
|
249
|
+
shareId: string,
|
|
250
|
+
secret: string,
|
|
251
|
+
actor: { userId: string; name: string; email: string } | undefined
|
|
252
|
+
): Promise<CommentActor> {
|
|
253
|
+
if (!options.sharing) throw new DocumentNotFoundError()
|
|
254
|
+
const resolution = await options.sharing.resolveShare(shareId, { secret }, actor)
|
|
255
|
+
const userId = resolution.principal.kind === 'user' ? resolution.principal.userId : null
|
|
256
|
+
return {
|
|
257
|
+
documentId: resolution.documentId,
|
|
258
|
+
userId,
|
|
259
|
+
canComment: userId !== null,
|
|
260
|
+
canModerate: userId !== null && resolution.permission === 'edit'
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
|
|
264
|
+
list,
|
|
265
|
+
|
|
266
|
+
async get(actor: CommentActor, threadId: string): Promise<CloudCommentThread> {
|
|
267
|
+
return readThread(
|
|
268
|
+
database,
|
|
269
|
+
await findThread(database, actor.documentId, threadId),
|
|
270
|
+
actor.userId
|
|
271
|
+
)
|
|
272
|
+
},
|
|
273
|
+
|
|
274
|
+
/** Records that the asker read the thread as it is now; a guest keeps no such record. */
|
|
275
|
+
async markRead(actor: CommentActor, threadId: string): Promise<void> {
|
|
276
|
+
if (actor.userId === null) return
|
|
277
|
+
await findThread(database, actor.documentId, threadId)
|
|
278
|
+
await markRead(database, actor.userId, threadId)
|
|
279
|
+
},
|
|
280
|
+
|
|
281
|
+
/** Which comments the account hears about by email. */
|
|
282
|
+
notificationSettings: (userId: string) => readNotificationSettings(database, userId),
|
|
283
|
+
setNotificationSettings: (userId: string, settings: NotificationSettings) =>
|
|
284
|
+
writeNotificationSettings(database, userId, settings),
|
|
285
|
+
|
|
286
|
+
/** Whom the asker may name in the document's comments. */
|
|
287
|
+
async people(actor: CommentActor) {
|
|
288
|
+
requireCommenter(actor)
|
|
289
|
+
return { people: await commentPeople(database, actor.documentId) }
|
|
290
|
+
},
|
|
291
|
+
|
|
292
|
+
async createThread(actor: CommentActor, input: NewThread): Promise<CloudCommentThread> {
|
|
293
|
+
const userId = requireCommenter(actor)
|
|
294
|
+
const threadId = input.id ?? crypto.randomUUID()
|
|
295
|
+
const thread = await database.transaction().execute(async (transaction) => {
|
|
296
|
+
// One writer at a time per document, so the count below holds until the insert.
|
|
297
|
+
await lockDocument(transaction, actor.documentId)
|
|
298
|
+
const existing = await transaction
|
|
299
|
+
.selectFrom('commentThread')
|
|
300
|
+
.select(['documentId', 'createdBy'])
|
|
301
|
+
.where('id', '=', threadId)
|
|
302
|
+
.executeTakeFirst()
|
|
303
|
+
if (existing) {
|
|
304
|
+
// The same request again, its answer lost on the way: the thread it made.
|
|
305
|
+
if (existing.documentId !== actor.documentId || existing.createdBy !== userId) {
|
|
306
|
+
throw new CommentConflictError()
|
|
307
|
+
}
|
|
308
|
+
return readThread(
|
|
309
|
+
transaction,
|
|
310
|
+
await findThread(transaction, actor.documentId, threadId),
|
|
311
|
+
actor.userId
|
|
312
|
+
)
|
|
313
|
+
}
|
|
314
|
+
if (
|
|
315
|
+
(await documentThreadCount(transaction, actor.documentId)) >=
|
|
316
|
+
MAX_COMMENT_THREADS_PER_DOCUMENT
|
|
317
|
+
) {
|
|
318
|
+
throw new CommentLimitError()
|
|
319
|
+
}
|
|
320
|
+
const now = new Date()
|
|
321
|
+
await transaction
|
|
322
|
+
.insertInto('commentThread')
|
|
323
|
+
.values({
|
|
324
|
+
id: threadId,
|
|
325
|
+
documentId: actor.documentId,
|
|
326
|
+
...anchorValues(input),
|
|
327
|
+
createdBy: userId,
|
|
328
|
+
createdAt: now,
|
|
329
|
+
updatedAt: now
|
|
330
|
+
})
|
|
331
|
+
.execute()
|
|
332
|
+
const commentId = crypto.randomUUID()
|
|
333
|
+
await transaction
|
|
334
|
+
.insertInto('comment')
|
|
335
|
+
.values({
|
|
336
|
+
id: commentId,
|
|
337
|
+
threadId,
|
|
338
|
+
authorId: userId,
|
|
339
|
+
agent: input.agent ?? null,
|
|
340
|
+
body: input.body,
|
|
341
|
+
createdAt: now
|
|
342
|
+
})
|
|
343
|
+
.execute()
|
|
344
|
+
await markRead(transaction, userId, threadId)
|
|
345
|
+
await tell(
|
|
346
|
+
transaction,
|
|
347
|
+
actor,
|
|
348
|
+
{ commentId, threadId, body: input.body },
|
|
349
|
+
input.mentions ?? []
|
|
350
|
+
)
|
|
351
|
+
return readThread(
|
|
352
|
+
transaction,
|
|
353
|
+
await findThread(transaction, actor.documentId, threadId),
|
|
354
|
+
actor.userId
|
|
355
|
+
)
|
|
356
|
+
})
|
|
357
|
+
announce(actor.documentId, threadId)
|
|
358
|
+
return thread
|
|
359
|
+
},
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Brings in the threads a file held as it moved to Cloud, for someone who may edit it. Their
|
|
363
|
+
* authors stay the names the file gave; the importer may move and resolve them as a starter.
|
|
364
|
+
*/
|
|
365
|
+
async importThreads(
|
|
366
|
+
actor: CommentActor,
|
|
367
|
+
input: ImportCommentThreadsInput
|
|
368
|
+
): Promise<CommentThreads> {
|
|
369
|
+
const userId = requireCommenter(actor)
|
|
370
|
+
if (!actor.canModerate) throw new DocumentForbiddenError()
|
|
371
|
+
const ids: string[] = []
|
|
372
|
+
if (input.threads.length > 0) {
|
|
373
|
+
await database.transaction().execute(async (transaction) => {
|
|
374
|
+
await lockDocument(transaction, actor.documentId)
|
|
375
|
+
const held = await documentThreadCount(transaction, actor.documentId)
|
|
376
|
+
if (held + input.threads.length > MAX_COMMENT_THREADS_PER_DOCUMENT) {
|
|
377
|
+
throw new CommentLimitError()
|
|
378
|
+
}
|
|
379
|
+
const now = new Date()
|
|
380
|
+
const rows = input.threads.map((thread) => ({
|
|
381
|
+
thread,
|
|
382
|
+
id: crypto.randomUUID(),
|
|
383
|
+
createdAt: new Date(thread.createdAt)
|
|
384
|
+
}))
|
|
385
|
+
const threadRows = rows.map(({ thread, id, createdAt }) => ({
|
|
386
|
+
id,
|
|
387
|
+
documentId: actor.documentId,
|
|
388
|
+
...anchorValues(thread),
|
|
389
|
+
createdBy: userId,
|
|
390
|
+
createdAt,
|
|
391
|
+
updatedAt: now,
|
|
392
|
+
resolvedAt: thread.resolved ? now : null,
|
|
393
|
+
resolvedBy: thread.resolved ? userId : null
|
|
394
|
+
}))
|
|
395
|
+
for (const batch of chunk(threadRows, INSERT_BATCH)) {
|
|
396
|
+
await transaction.insertInto('commentThread').values(batch).execute()
|
|
397
|
+
}
|
|
398
|
+
const imported = rows.flatMap(({ thread, id }) =>
|
|
399
|
+
importedTimes(thread.comments.map((comment) => comment.createdAt)).map(
|
|
400
|
+
(createdAt, index) => ({
|
|
401
|
+
id: crypto.randomUUID(),
|
|
402
|
+
threadId: id,
|
|
403
|
+
authorId: null,
|
|
404
|
+
importedAuthorName: thread.comments[index]?.authorName ?? '',
|
|
405
|
+
body: thread.comments[index]?.body ?? '',
|
|
406
|
+
createdAt
|
|
407
|
+
})
|
|
408
|
+
)
|
|
409
|
+
)
|
|
410
|
+
// A statement takes so many parameters; a big file's comments go in a few.
|
|
411
|
+
for (const batch of chunk(imported, INSERT_BATCH)) {
|
|
412
|
+
await transaction.insertInto('comment').values(batch).execute()
|
|
413
|
+
}
|
|
414
|
+
// The importer has read what they brought.
|
|
415
|
+
for (const { id } of rows) {
|
|
416
|
+
await markRead(transaction, userId, id)
|
|
417
|
+
ids.push(id)
|
|
418
|
+
}
|
|
419
|
+
})
|
|
420
|
+
}
|
|
421
|
+
for (const id of ids) announce(actor.documentId, id)
|
|
422
|
+
return list(actor)
|
|
423
|
+
},
|
|
424
|
+
|
|
425
|
+
async updateThread(
|
|
426
|
+
actor: CommentActor,
|
|
427
|
+
threadId: string,
|
|
428
|
+
input: UpdateCommentThreadInput
|
|
429
|
+
): Promise<CloudCommentThread> {
|
|
430
|
+
const userId = requireCommenter(actor)
|
|
431
|
+
const thread = await database.transaction().execute(async (transaction) => {
|
|
432
|
+
const row = await findThread(transaction, actor.documentId, threadId, true)
|
|
433
|
+
if (input.anchor && row.createdBy !== userId && !actor.canModerate) {
|
|
434
|
+
throw new DocumentForbiddenError()
|
|
435
|
+
}
|
|
436
|
+
const changes = {
|
|
437
|
+
...(input.anchor ? anchorValues(input.anchor) : {}),
|
|
438
|
+
...resolutionChange(input.resolved, row.resolvedAt !== null, userId)
|
|
439
|
+
}
|
|
440
|
+
// Resolving what is already resolved, and nothing else, changes nothing.
|
|
441
|
+
if (isEmptyObject(changes)) return readThread(transaction, row, actor.userId)
|
|
442
|
+
await transaction
|
|
443
|
+
.updateTable('commentThread')
|
|
444
|
+
.set(changes)
|
|
445
|
+
.where('id', '=', threadId)
|
|
446
|
+
.execute()
|
|
447
|
+
return touched(transaction, actor, threadId)
|
|
448
|
+
})
|
|
449
|
+
announce(actor.documentId, threadId)
|
|
450
|
+
return thread
|
|
451
|
+
},
|
|
452
|
+
|
|
453
|
+
async deleteThread(actor: CommentActor, threadId: string): Promise<void> {
|
|
454
|
+
const userId = requireCommenter(actor)
|
|
455
|
+
await database.transaction().execute(async (transaction) => {
|
|
456
|
+
const row = await findThread(transaction, actor.documentId, threadId, true)
|
|
457
|
+
if (row.createdBy !== userId && !actor.canModerate) throw new DocumentForbiddenError()
|
|
458
|
+
await transaction.deleteFrom('commentThread').where('id', '=', threadId).execute()
|
|
459
|
+
})
|
|
460
|
+
announce(actor.documentId, threadId)
|
|
461
|
+
},
|
|
462
|
+
|
|
463
|
+
async reply(
|
|
464
|
+
actor: CommentActor,
|
|
465
|
+
threadId: string,
|
|
466
|
+
input: NewComment
|
|
467
|
+
): Promise<CloudCommentThread> {
|
|
468
|
+
const userId = requireCommenter(actor)
|
|
469
|
+
const commentId = input.id ?? crypto.randomUUID()
|
|
470
|
+
const thread = await database.transaction().execute(async (transaction) => {
|
|
471
|
+
await findThread(transaction, actor.documentId, threadId, true)
|
|
472
|
+
const existing = await transaction
|
|
473
|
+
.selectFrom('comment')
|
|
474
|
+
.select(['threadId', 'authorId'])
|
|
475
|
+
.where('id', '=', commentId)
|
|
476
|
+
.executeTakeFirst()
|
|
477
|
+
if (existing) {
|
|
478
|
+
if (existing.threadId !== threadId || existing.authorId !== userId) {
|
|
479
|
+
throw new CommentConflictError()
|
|
480
|
+
}
|
|
481
|
+
return readThread(
|
|
482
|
+
transaction,
|
|
483
|
+
await findThread(transaction, actor.documentId, threadId),
|
|
484
|
+
actor.userId
|
|
485
|
+
)
|
|
486
|
+
}
|
|
487
|
+
const { count } = await transaction
|
|
488
|
+
.selectFrom('comment')
|
|
489
|
+
.select((expression) => expression.fn.countAll<string>().as('count'))
|
|
490
|
+
.where('threadId', '=', threadId)
|
|
491
|
+
.executeTakeFirstOrThrow()
|
|
492
|
+
if (Number(count) >= MAX_COMMENTS_PER_THREAD) throw new CommentLimitError()
|
|
493
|
+
await transaction
|
|
494
|
+
.insertInto('comment')
|
|
495
|
+
.values({
|
|
496
|
+
id: commentId,
|
|
497
|
+
threadId,
|
|
498
|
+
authorId: userId,
|
|
499
|
+
agent: input.agent ?? null,
|
|
500
|
+
body: input.body
|
|
501
|
+
})
|
|
502
|
+
.execute()
|
|
503
|
+
await tell(
|
|
504
|
+
transaction,
|
|
505
|
+
actor,
|
|
506
|
+
{ commentId, threadId, body: input.body },
|
|
507
|
+
input.mentions ?? [],
|
|
508
|
+
{
|
|
509
|
+
reply: true
|
|
510
|
+
}
|
|
511
|
+
)
|
|
512
|
+
return touched(transaction, actor, threadId)
|
|
513
|
+
})
|
|
514
|
+
announce(actor.documentId, threadId)
|
|
515
|
+
return thread
|
|
516
|
+
},
|
|
517
|
+
|
|
518
|
+
/** Changes what a comment says; only its author may, so no one puts words in another's mouth. */
|
|
519
|
+
async updateComment(
|
|
520
|
+
actor: CommentActor,
|
|
521
|
+
threadId: string,
|
|
522
|
+
commentId: string,
|
|
523
|
+
input: CommentEdit
|
|
524
|
+
): Promise<CloudCommentThread> {
|
|
525
|
+
const userId = requireCommenter(actor)
|
|
526
|
+
const thread = await database.transaction().execute(async (transaction) => {
|
|
527
|
+
const comment = await lockedComment(transaction, actor, threadId, commentId)
|
|
528
|
+
if (comment.authorId !== userId) throw new DocumentForbiddenError()
|
|
529
|
+
await transaction
|
|
530
|
+
.updateTable('comment')
|
|
531
|
+
.set({ body: input.body, editedAt: new Date() })
|
|
532
|
+
.where('id', '=', commentId)
|
|
533
|
+
.execute()
|
|
534
|
+
// An edit tells only the people it names that it did not before.
|
|
535
|
+
await tell(
|
|
536
|
+
transaction,
|
|
537
|
+
actor,
|
|
538
|
+
{ commentId, threadId, body: input.body },
|
|
539
|
+
input.mentions ?? []
|
|
540
|
+
)
|
|
541
|
+
return touched(transaction, actor, threadId)
|
|
542
|
+
})
|
|
543
|
+
announce(actor.documentId, threadId)
|
|
544
|
+
return thread
|
|
545
|
+
},
|
|
546
|
+
|
|
547
|
+
/** Deletes a comment for good; the thread goes with its first one. Null once it is gone. */
|
|
548
|
+
async deleteComment(
|
|
549
|
+
actor: CommentActor,
|
|
550
|
+
threadId: string,
|
|
551
|
+
commentId: string
|
|
552
|
+
): Promise<CloudCommentThread | null> {
|
|
553
|
+
const userId = requireCommenter(actor)
|
|
554
|
+
const thread = await database.transaction().execute(async (transaction) => {
|
|
555
|
+
const comment = await lockedComment(transaction, actor, threadId, commentId)
|
|
556
|
+
if (comment.authorId !== userId && !actor.canModerate) throw new DocumentForbiddenError()
|
|
557
|
+
if (comment.first) {
|
|
558
|
+
await transaction.deleteFrom('commentThread').where('id', '=', threadId).execute()
|
|
559
|
+
return null
|
|
560
|
+
}
|
|
561
|
+
await transaction.deleteFrom('comment').where('id', '=', commentId).execute()
|
|
562
|
+
return touched(transaction, actor, threadId)
|
|
563
|
+
})
|
|
564
|
+
announce(actor.documentId, threadId)
|
|
565
|
+
return thread
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
export type CommentService = ReturnType<typeof createCommentService>
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
COMMUNITY_THUMBNAIL_PATH,
|
|
3
|
+
communityDownloadQuerySchema,
|
|
4
|
+
requestImageLinksSchema
|
|
5
|
+
} from '#cloud/contract'
|
|
6
|
+
import { documentDomainError } from '#cloud/server/documents'
|
|
7
|
+
import {
|
|
8
|
+
documentRevisionParams,
|
|
9
|
+
documentParams,
|
|
10
|
+
validatedJSON,
|
|
11
|
+
validatedQuery
|
|
12
|
+
} from '#cloud/server/validation'
|
|
13
|
+
import { Hono, type Context } from 'hono'
|
|
14
|
+
|
|
15
|
+
import type { CommunityService } from './service'
|
|
16
|
+
|
|
17
|
+
const notFound = (context: Context) => context.json({ error: { code: 'not_found' as const } }, 404)
|
|
18
|
+
|
|
19
|
+
/** Answers a missing or hidden gallery document as not found, like any document outside it. */
|
|
20
|
+
async function communityRoute(context: Context, action: () => Promise<Response>) {
|
|
21
|
+
try {
|
|
22
|
+
return await action()
|
|
23
|
+
} catch (error) {
|
|
24
|
+
const response = documentDomainError(context, error)
|
|
25
|
+
if (response) return response
|
|
26
|
+
throw error
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The community gallery's data for anyone, signed in or not: the list, a document or one of its
|
|
32
|
+
* named versions to open read-only, and the links of its images. A deployment without a gallery
|
|
33
|
+
* answers not found.
|
|
34
|
+
*/
|
|
35
|
+
export function createCommunityRoutes(community: CommunityService) {
|
|
36
|
+
return new Hono()
|
|
37
|
+
.get('/community', async (context) => {
|
|
38
|
+
if (!community.enabled) return notFound(context)
|
|
39
|
+
// The gallery changes on a publish; a few minutes' copy spares the database repeat visits.
|
|
40
|
+
context.header('Cache-Control', 'public, max-age=300')
|
|
41
|
+
return context.json({ documents: await community.list() })
|
|
42
|
+
})
|
|
43
|
+
.get(
|
|
44
|
+
'/community/:documentId/document',
|
|
45
|
+
documentParams,
|
|
46
|
+
validatedQuery(communityDownloadQuerySchema),
|
|
47
|
+
(context) =>
|
|
48
|
+
communityRoute(context, async () => {
|
|
49
|
+
const { documentId } = context.req.valid('param')
|
|
50
|
+
return context.json(
|
|
51
|
+
await community.download(documentId, context.req.valid('query').version)
|
|
52
|
+
)
|
|
53
|
+
})
|
|
54
|
+
)
|
|
55
|
+
.post(
|
|
56
|
+
'/community/:documentId/images',
|
|
57
|
+
documentParams,
|
|
58
|
+
validatedJSON(requestImageLinksSchema),
|
|
59
|
+
(context) =>
|
|
60
|
+
communityRoute(context, async () =>
|
|
61
|
+
context.json(
|
|
62
|
+
await community.imageLinks(
|
|
63
|
+
context.req.valid('param').documentId,
|
|
64
|
+
context.req.valid('json').checksums
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Gallery thumbnails, for pages and apps on any origin. Each address names the revision it shows,
|
|
73
|
+
* so a copy never goes stale, but it is cached only as long as the listing is: a document taken
|
|
74
|
+
* down or out of the gallery stops showing everywhere within minutes.
|
|
75
|
+
*/
|
|
76
|
+
export function createCommunityThumbnailRoutes(community: CommunityService) {
|
|
77
|
+
return new Hono().get(
|
|
78
|
+
`${COMMUNITY_THUMBNAIL_PATH}/:documentId/:revisionId`,
|
|
79
|
+
documentRevisionParams,
|
|
80
|
+
(context) =>
|
|
81
|
+
communityRoute(context, async () => {
|
|
82
|
+
const { documentId, revisionId } = context.req.valid('param')
|
|
83
|
+
const thumbnail = await community.thumbnail(documentId, revisionId)
|
|
84
|
+
if (!thumbnail) return notFound(context)
|
|
85
|
+
context.header('Cache-Control', 'public, max-age=300')
|
|
86
|
+
context.header('Content-Type', 'image/png')
|
|
87
|
+
context.header('X-Content-Type-Options', 'nosniff')
|
|
88
|
+
context.header('Content-Security-Policy', "default-src 'none'; sandbox")
|
|
89
|
+
context.header('Cross-Origin-Resource-Policy', 'cross-origin')
|
|
90
|
+
return context.body(new Uint8Array(thumbnail))
|
|
91
|
+
})
|
|
92
|
+
)
|
|
93
|
+
}
|