@jant/core 0.3.46 → 0.3.47
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/bin/commands/db/execute-file.js +12 -4
- package/bin/commands/db/rehearse.js +2 -2
- package/bin/commands/export.js +12 -4
- package/bin/commands/import-site.js +60 -267
- package/bin/commands/migrate.js +36 -69
- package/bin/commands/reset-password.js +10 -4
- package/bin/commands/site/export.js +59 -248
- package/bin/commands/site/snapshot/export.js +58 -45
- package/bin/commands/site/snapshot/import.js +104 -52
- package/bin/lib/node-env.js +100 -0
- package/bin/lib/runtime-target.js +64 -0
- package/bin/lib/site-snapshot.js +185 -54
- package/bin/lib/sql-export.js +19 -2
- package/dist/{app-DB-P66E5.js → app-3REcR-3U.js} +331 -189
- package/dist/app-B67XOEyo.js +6 -0
- package/dist/client/.vite/manifest.json +2 -2
- package/dist/client/_assets/{client-auth-BLCUje4M.js → client-auth-Ce5WEAVS.js} +102 -49
- package/dist/client/_assets/client-s71Js1Cu.css +2 -0
- package/dist/{github-sync-CQ1x271f.js → export-ZBlfKSKm.js} +12 -439
- package/dist/github-sync-C593r22F.js +4 -0
- package/dist/github-sync-bL1hnx3Q.js +428 -0
- package/dist/index.js +3 -2
- package/dist/node.js +5 -4
- package/package.json +3 -2
- package/src/__tests__/helpers/export-fixtures.ts +0 -1
- package/src/client/components/__tests__/jant-settings-avatar.test.ts +2 -0
- package/src/client/components/__tests__/jant-settings-general.test.ts +70 -0
- package/src/client/components/jant-settings-general.ts +164 -22
- package/src/client/components/settings-types.ts +4 -6
- package/src/client-auth.ts +1 -1
- package/src/db/__tests__/demo-canonical-snapshot.test.ts +1 -1
- package/src/db/__tests__/migration-rehearsal.test.ts +2 -5
- package/src/db/backfills/0004_register_apple_touch_media_rows.sql +65 -0
- package/src/db/migrations/0021_thankful_phalanx.sql +16 -0
- package/src/db/migrations/meta/0021_snapshot.json +2121 -0
- package/src/db/migrations/meta/_journal.json +7 -0
- package/src/db/migrations/pg/0019_gray_natasha_romanoff.sql +20 -0
- package/src/db/migrations/pg/meta/0019_snapshot.json +2718 -0
- package/src/db/migrations/pg/meta/_journal.json +7 -0
- package/src/db/pg/schema.ts +21 -26
- package/src/db/rehearsal-fixtures/demo-current.json +1 -1
- package/src/db/schema.ts +16 -20
- package/src/i18n/__tests__/middleware.test.ts +43 -1
- package/src/i18n/coverage.generated.ts +17 -0
- package/src/i18n/i18n.ts +18 -2
- package/src/i18n/index.ts +3 -0
- package/src/i18n/locales/settings/en.po +16 -11
- package/src/i18n/locales/settings/en.ts +1 -1
- package/src/i18n/locales/settings/zh-Hans.po +17 -12
- package/src/i18n/locales/settings/zh-Hans.ts +1 -1
- package/src/i18n/locales/settings/zh-Hant.po +16 -11
- package/src/i18n/locales/settings/zh-Hant.ts +1 -1
- package/src/i18n/locales.ts +84 -2
- package/src/i18n/middleware.ts +25 -16
- package/src/i18n/supported-locales.ts +153 -0
- package/src/lib/__tests__/csp-builder.test.ts +19 -2
- package/src/lib/__tests__/feed.test.ts +242 -1
- package/src/lib/__tests__/post-meta.test.ts +0 -1
- package/src/lib/__tests__/view.test.ts +0 -1
- package/src/lib/csp-builder.ts +28 -10
- package/src/lib/feed.ts +153 -3
- package/src/middleware/__tests__/secure-headers.test.ts +89 -0
- package/src/middleware/auth.ts +1 -1
- package/src/middleware/secure-headers.ts +47 -1
- package/src/node/__tests__/cli-runtime-target.test.ts +110 -2
- package/src/node/__tests__/cli-site-snapshot.test.ts +308 -13
- package/src/node/__tests__/cli-site-token-env.test.ts +2 -7
- package/src/node/__tests__/cli-snapshot-meta.test.ts +85 -0
- package/src/node/__tests__/cli-sql-export.test.ts +49 -0
- package/src/node/index.ts +1 -0
- package/src/preset.css +8 -2
- package/src/routes/api/__tests__/settings.test.ts +3 -2
- package/src/routes/api/github-sync.tsx +1 -1
- package/src/routes/api/settings.ts +4 -1
- package/src/routes/auth/signin.tsx +6 -0
- package/src/routes/pages/archive.tsx +4 -2
- package/src/services/__tests__/post.test.ts +19 -19
- package/src/services/__tests__/search.test.ts +0 -1
- package/src/services/__tests__/settings.test.ts +22 -3
- package/src/services/bootstrap.ts +7 -3
- package/src/services/collection.ts +3 -3
- package/src/services/export.ts +0 -3
- package/src/services/navigation.ts +0 -2
- package/src/services/path.ts +1 -38
- package/src/services/post.ts +32 -66
- package/src/services/search.ts +0 -6
- package/src/services/settings.ts +47 -6
- package/src/services/site-admin.ts +6 -1
- package/src/styles/ui.css +12 -23
- package/src/types/entities.ts +0 -1
- package/src/ui/color-themes.ts +1 -1
- package/src/ui/dash/settings/GeneralContent.tsx +17 -19
- package/src/ui/dash/settings/SettingsRootContent.tsx +17 -28
- package/src/ui/feed/NoteCard.tsx +1 -11
- package/src/ui/feed/__tests__/timeline-cards.test.ts +1 -1
- package/src/ui/pages/PostPage.tsx +2 -0
- package/bin/commands/collections.js +0 -268
- package/bin/commands/media.js +0 -302
- package/bin/commands/posts.js +0 -262
- package/bin/commands/search.js +0 -53
- package/bin/commands/settings.js +0 -93
- package/bin/lib/http-api.js +0 -223
- package/bin/lib/media-upload.js +0 -206
- package/dist/app-CM7sb3xO.js +0 -5
- package/dist/client/_assets/client-DDs6NzB3.css +0 -2
- package/src/__tests__/bin/content-cli.test.ts +0 -179
- package/src/__tests__/bin/media-cli.test.ts +0 -192
- /package/dist/{github-api-BkRWnqMx.js → github-api-Bh0PH3zr.js} +0 -0
- /package/dist/{github-app-WeadXMb8.js → github-app-D0GvNnqp.js} +0 -0
package/bin/lib/media-upload.js
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import { basename, extname } from "node:path";
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
-
import { requestJson, requestRaw, resolveRequestUrl } from "./http-api.js";
|
|
4
|
-
|
|
5
|
-
const MIME_TYPES = {
|
|
6
|
-
".avif": "image/avif",
|
|
7
|
-
".csv": "text/csv",
|
|
8
|
-
".gif": "image/gif",
|
|
9
|
-
".heic": "image/heic",
|
|
10
|
-
".jpeg": "image/jpeg",
|
|
11
|
-
".jpg": "image/jpeg",
|
|
12
|
-
".json": "application/json",
|
|
13
|
-
".md": "text/markdown",
|
|
14
|
-
".mov": "video/quicktime",
|
|
15
|
-
".mp3": "audio/mpeg",
|
|
16
|
-
".mp4": "video/mp4",
|
|
17
|
-
".pdf": "application/pdf",
|
|
18
|
-
".png": "image/png",
|
|
19
|
-
".svg": "image/svg+xml",
|
|
20
|
-
".txt": "text/plain",
|
|
21
|
-
".wav": "audio/wav",
|
|
22
|
-
".webm": "video/webm",
|
|
23
|
-
".webp": "image/webp",
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
function inferContentType(filePath, explicitContentType) {
|
|
27
|
-
const trimmed = explicitContentType?.trim();
|
|
28
|
-
if (trimmed) {
|
|
29
|
-
return trimmed;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const ext = extname(filePath).toLowerCase();
|
|
33
|
-
const inferred = MIME_TYPES[ext];
|
|
34
|
-
if (inferred) {
|
|
35
|
-
return inferred;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
throw new Error(
|
|
39
|
-
`Couldn't infer a content type for ${filePath}. Pass --content-type explicitly.`,
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function buildCompletePayload(metadata, parts) {
|
|
44
|
-
return {
|
|
45
|
-
...(metadata.width === undefined ? {} : { width: metadata.width }),
|
|
46
|
-
...(metadata.height === undefined ? {} : { height: metadata.height }),
|
|
47
|
-
...(metadata.durationSeconds === undefined
|
|
48
|
-
? {}
|
|
49
|
-
: { durationSeconds: metadata.durationSeconds }),
|
|
50
|
-
...(metadata.blurhash === undefined ? {} : { blurhash: metadata.blurhash }),
|
|
51
|
-
...(metadata.waveform === undefined ? {} : { waveform: metadata.waveform }),
|
|
52
|
-
...(metadata.summary === undefined ? {} : { summary: metadata.summary }),
|
|
53
|
-
...(metadata.chars === undefined ? {} : { chars: metadata.chars }),
|
|
54
|
-
...(parts ? { parts } : {}),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async function uploadTransportBytes({ fileBytes, siteUrl, token, transport }) {
|
|
59
|
-
switch (transport.kind) {
|
|
60
|
-
case "relay": {
|
|
61
|
-
await requestRaw({
|
|
62
|
-
body: fileBytes,
|
|
63
|
-
method: "PUT",
|
|
64
|
-
token,
|
|
65
|
-
url: resolveRequestUrl(siteUrl, transport.url),
|
|
66
|
-
});
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
case "put": {
|
|
70
|
-
await requestRaw({
|
|
71
|
-
body: fileBytes,
|
|
72
|
-
headers: transport.headers,
|
|
73
|
-
method: transport.method,
|
|
74
|
-
url: transport.url,
|
|
75
|
-
});
|
|
76
|
-
return undefined;
|
|
77
|
-
}
|
|
78
|
-
case "multipartRelay": {
|
|
79
|
-
const parts = [];
|
|
80
|
-
|
|
81
|
-
for (
|
|
82
|
-
let offset = 0, partNumber = 1;
|
|
83
|
-
offset < fileBytes.byteLength;
|
|
84
|
-
offset += transport.partSize, partNumber += 1
|
|
85
|
-
) {
|
|
86
|
-
const partUrl = new URL(resolveRequestUrl(siteUrl, transport.url));
|
|
87
|
-
partUrl.searchParams.set("partNumber", String(partNumber));
|
|
88
|
-
const chunk = fileBytes.subarray(offset, offset + transport.partSize);
|
|
89
|
-
const { json } = await requestRaw({
|
|
90
|
-
body: chunk,
|
|
91
|
-
method: "PUT",
|
|
92
|
-
token,
|
|
93
|
-
url: partUrl.toString(),
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
parts.push(json);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return parts;
|
|
100
|
-
}
|
|
101
|
-
default:
|
|
102
|
-
throw new Error(`Unsupported upload transport: ${transport.kind}`);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export async function uploadMediaFile({
|
|
107
|
-
alt,
|
|
108
|
-
blurhash,
|
|
109
|
-
chars,
|
|
110
|
-
contentType,
|
|
111
|
-
durationSeconds,
|
|
112
|
-
filePath,
|
|
113
|
-
height,
|
|
114
|
-
posterPath,
|
|
115
|
-
siteUrl,
|
|
116
|
-
summary,
|
|
117
|
-
token,
|
|
118
|
-
waveform,
|
|
119
|
-
width,
|
|
120
|
-
}) {
|
|
121
|
-
const fileBytes = await readFile(filePath);
|
|
122
|
-
const resolvedContentType = inferContentType(filePath, contentType);
|
|
123
|
-
const filename = basename(filePath);
|
|
124
|
-
const init = await requestJson({
|
|
125
|
-
siteUrl,
|
|
126
|
-
path: "/api/uploads/init",
|
|
127
|
-
method: "POST",
|
|
128
|
-
token,
|
|
129
|
-
body: {
|
|
130
|
-
filename,
|
|
131
|
-
contentType: resolvedContentType,
|
|
132
|
-
size: fileBytes.byteLength,
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
if (
|
|
137
|
-
!init ||
|
|
138
|
-
typeof init !== "object" ||
|
|
139
|
-
!("id" in init) ||
|
|
140
|
-
!("transport" in init) ||
|
|
141
|
-
!init.transport ||
|
|
142
|
-
typeof init.transport !== "object" ||
|
|
143
|
-
!("kind" in init.transport)
|
|
144
|
-
) {
|
|
145
|
-
throw new Error("Upload init returned an unexpected response.");
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const parts = await uploadTransportBytes({
|
|
149
|
-
fileBytes,
|
|
150
|
-
siteUrl,
|
|
151
|
-
token,
|
|
152
|
-
transport: init.transport,
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
if (posterPath?.trim()) {
|
|
156
|
-
const posterBytes = await readFile(posterPath);
|
|
157
|
-
await requestRaw({
|
|
158
|
-
body: posterBytes,
|
|
159
|
-
method: "PUT",
|
|
160
|
-
token,
|
|
161
|
-
url: resolveRequestUrl(siteUrl, `/api/uploads/${init.id}/poster`),
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const complete = await requestJson({
|
|
166
|
-
siteUrl,
|
|
167
|
-
path: `/api/uploads/${init.id}/complete`,
|
|
168
|
-
method: "POST",
|
|
169
|
-
token,
|
|
170
|
-
body: buildCompletePayload(
|
|
171
|
-
{
|
|
172
|
-
alt,
|
|
173
|
-
blurhash,
|
|
174
|
-
chars,
|
|
175
|
-
durationSeconds,
|
|
176
|
-
height,
|
|
177
|
-
summary,
|
|
178
|
-
waveform,
|
|
179
|
-
width,
|
|
180
|
-
},
|
|
181
|
-
Array.isArray(parts) ? parts : undefined,
|
|
182
|
-
),
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
if (!complete || typeof complete !== "object" || !("id" in complete)) {
|
|
186
|
-
throw new Error("Upload complete returned an unexpected response.");
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
if (alt !== undefined) {
|
|
190
|
-
return requestJson({
|
|
191
|
-
siteUrl,
|
|
192
|
-
path: `/api/upload/${complete.id}`,
|
|
193
|
-
method: "PATCH",
|
|
194
|
-
token,
|
|
195
|
-
body: {
|
|
196
|
-
alt,
|
|
197
|
-
},
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return requestJson({
|
|
202
|
-
siteUrl,
|
|
203
|
-
path: `/api/upload/${complete.id}`,
|
|
204
|
-
token,
|
|
205
|
-
});
|
|
206
|
-
}
|