@workover/cli 0.14.1 → 0.15.0
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 +30 -0
- package/bin/workover.mjs +124 -10
- package/lib.mjs +106 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -296,6 +296,36 @@ writing, the structure and the pictures alone. Like `reshoot`, it needs `workove
|
|
|
296
296
|
and `--write` needs `--write` too. A project with no linked repository has nothing to check
|
|
297
297
|
against, so the command says so rather than pretending to have checked.
|
|
298
298
|
|
|
299
|
+
### Drafting the WordPress post
|
|
300
|
+
|
|
301
|
+
`workover doc wp-draft` creates the WordPress post a document will publish to, as a draft, and
|
|
302
|
+
links the two. The person who opens the document then publishes it with one click, into the right
|
|
303
|
+
content type, with nothing to fill in. It is for a scheduled writer, such as a weekly changelog,
|
|
304
|
+
that drafts in Workover and leaves publishing to a person.
|
|
305
|
+
|
|
306
|
+
```sh
|
|
307
|
+
workover doc wp-draft 1234 --type changelog
|
|
308
|
+
workover doc wp-draft 1234 --type changelog --slug weekly-update \
|
|
309
|
+
--excerpt "One line for feeds" --taxonomies '{"changelog_product":[50,52]}' --acf '{"summary":"…"}'
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
It always creates a draft; nothing run from the CLI puts a page live. A document that is already
|
|
313
|
+
on WordPress is refused, since a second post would split it in two. It needs
|
|
314
|
+
`workover login --publish`.
|
|
315
|
+
|
|
316
|
+
### Uploading a screenshot
|
|
317
|
+
|
|
318
|
+
`workover doc upload` puts an image into a document's media and prints the markdown that places it,
|
|
319
|
+
for a scheduled job that captures screenshots and then proposes them into a draft.
|
|
320
|
+
|
|
321
|
+
```sh
|
|
322
|
+
workover doc upload 1234 inbox.png --alt "Inbox → Suggestions with a spelling fix open"
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
Nothing in the document changes until that markdown is written or proposed. Only PNG, JPEG, GIF and
|
|
326
|
+
WebP files up to 5 MB are sent, never one inside a hidden (dot) directory, and symlinks are judged by
|
|
327
|
+
what they point to.
|
|
328
|
+
|
|
299
329
|
## Coworking with Claude Code
|
|
300
330
|
|
|
301
331
|
Pair it with the [Workover MCP server](https://www.npmjs.com/package/@workover/mcp):
|
package/bin/workover.mjs
CHANGED
|
@@ -13,8 +13,9 @@ import {
|
|
|
13
13
|
writeFileSync,
|
|
14
14
|
mkdirSync,
|
|
15
15
|
existsSync,
|
|
16
|
-
chmodSync,
|
|
17
16
|
rmSync,
|
|
17
|
+
realpathSync,
|
|
18
|
+
statSync,
|
|
18
19
|
} from 'fs';
|
|
19
20
|
import { homedir } from 'os';
|
|
20
21
|
import { dirname, join } from 'path';
|
|
@@ -23,6 +24,7 @@ import { fileURLToPath } from 'url';
|
|
|
23
24
|
import {
|
|
24
25
|
normalizeApi,
|
|
25
26
|
browserCommand,
|
|
27
|
+
writePrivateFile,
|
|
26
28
|
pollDecision,
|
|
27
29
|
summariseEvaluations,
|
|
28
30
|
parseArgs,
|
|
@@ -36,6 +38,8 @@ import {
|
|
|
36
38
|
environmentMismatch,
|
|
37
39
|
imagesInHtml,
|
|
38
40
|
signInHelp,
|
|
41
|
+
jsonObjectFlag,
|
|
42
|
+
vetImageUpload,
|
|
39
43
|
} from '../lib.mjs';
|
|
40
44
|
|
|
41
45
|
/*
|
|
@@ -56,13 +60,9 @@ const API = normalizeApi(process.env.WORKOVER_API || 'https://api.workover.io');
|
|
|
56
60
|
// preview) can be used without replacing the one in ~/.workover. The MCP server reads the same
|
|
57
61
|
// variable, so both see the same sign-in.
|
|
58
62
|
const CONFIG_FILE = process.env.WORKOVER_CONFIG || join(homedir(), '.workover', 'config.json');
|
|
59
|
-
const CONFIG_DIR = dirname(CONFIG_FILE);
|
|
60
63
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
writeFileSync(CONFIG_FILE, JSON.stringify(cfg, null, 2));
|
|
64
|
-
chmodSync(CONFIG_FILE, 0o600); // owner read/write only — it holds a bearer token
|
|
65
|
-
};
|
|
64
|
+
// Owner read/write only, from the first byte — it holds a bearer token (see writePrivateFile).
|
|
65
|
+
const saveConfig = (cfg) => writePrivateFile(CONFIG_FILE, JSON.stringify(cfg, null, 2));
|
|
66
66
|
const loadConfig = () => {
|
|
67
67
|
try {
|
|
68
68
|
return JSON.parse(readFileSync(CONFIG_FILE, 'utf8'));
|
|
@@ -72,7 +72,9 @@ const loadConfig = () => {
|
|
|
72
72
|
};
|
|
73
73
|
|
|
74
74
|
const openBrowser = (url) => {
|
|
75
|
-
const
|
|
75
|
+
const command = browserCommand(process.platform, url);
|
|
76
|
+
if (!command) return; // not an http(s) URL — it is printed anyway
|
|
77
|
+
const { cmd, args } = command;
|
|
76
78
|
try {
|
|
77
79
|
spawn(cmd, args, { stdio: 'ignore', detached: true }).unref();
|
|
78
80
|
} catch {
|
|
@@ -235,7 +237,6 @@ async function login() {
|
|
|
235
237
|
|
|
236
238
|
async function logout() {
|
|
237
239
|
const cfg = loadConfig();
|
|
238
|
-
let revoked = true;
|
|
239
240
|
if (cfg?.token) {
|
|
240
241
|
/*
|
|
241
242
|
* Revoke on the api this sign-in BELONGS to, which login recorded as `cfg.api`.
|
|
@@ -247,7 +248,7 @@ async function logout() {
|
|
|
247
248
|
* Possessing the token authorizes revoking it; best-effort, but no longer silent when it fails.
|
|
248
249
|
*/
|
|
249
250
|
const base = cfg.api ? normalizeApi(cfg.api) : API;
|
|
250
|
-
revoked = await fetch(`${base}/cli-auth/logout`, {
|
|
251
|
+
const revoked = await fetch(`${base}/cli-auth/logout`, {
|
|
251
252
|
method: 'POST',
|
|
252
253
|
headers: { 'content-type': 'application/json' },
|
|
253
254
|
body: JSON.stringify({ token: cfg.token }),
|
|
@@ -789,6 +790,12 @@ const DOC_USAGE = [
|
|
|
789
790
|
' the linked repository and corrects what it finds wrong;',
|
|
790
791
|
' applied as suggestions, or directly with --write. Needs',
|
|
791
792
|
' `login --draft`',
|
|
793
|
+
' wp-draft <doc> --type <post type> create the WordPress DRAFT of this',
|
|
794
|
+
' [--slug <s>] [--excerpt "<t>"] document, linked to it, on its project\u2019s',
|
|
795
|
+
' [--taxonomies <json>] site. Never live: Publish stays a click',
|
|
796
|
+
' [--acf <json>] [--json] in Workover. Needs `login --publish`',
|
|
797
|
+
' upload <doc> <image> [--alt "<text>"] upload a screenshot into the document’s',
|
|
798
|
+
' [--json] media; prints the markdown to place it',
|
|
792
799
|
' images <doc> [--tab <tabId>] [--json] the images in it: file name, alt',
|
|
793
800
|
' image <doc> <n | --src <url>> set an image’s file name and/or',
|
|
794
801
|
' [--name <file>] [--alt "<text>"] alt text; needs `login --write`',
|
|
@@ -989,6 +996,8 @@ async function docCommand() {
|
|
|
989
996
|
'activity',
|
|
990
997
|
'reshoot',
|
|
991
998
|
'verify',
|
|
999
|
+
'wp-draft',
|
|
1000
|
+
'upload',
|
|
992
1001
|
'images',
|
|
993
1002
|
'image',
|
|
994
1003
|
].includes(sub)
|
|
@@ -1384,6 +1393,111 @@ async function docCommand() {
|
|
|
1384
1393
|
return;
|
|
1385
1394
|
}
|
|
1386
1395
|
|
|
1396
|
+
if (sub === 'wp-draft') {
|
|
1397
|
+
// A scheduled writer (Scout's weekly changelog) drafts a post here and a person publishes it.
|
|
1398
|
+
// That only works if the document is ALREADY linked to a WordPress post of the right type when
|
|
1399
|
+
// the person opens it, so Publish is one click and lands in the right content type. The API's
|
|
1400
|
+
// publish route creates and links that post; this always sends `status: draft`, so nothing an
|
|
1401
|
+
// agent runs from here can put a page live.
|
|
1402
|
+
const usage =
|
|
1403
|
+
'workover doc wp-draft <doc> --type <post type> [--slug <s>] [--excerpt "<text>"] [--taxonomies <json>] [--acf <json>]';
|
|
1404
|
+
const docId = await resolveDocArg(cfg, positionals, usage);
|
|
1405
|
+
const type = typeof flags.type === 'string' ? flags.type.trim() : '';
|
|
1406
|
+
if (!type) {
|
|
1407
|
+
console.log(`\n Usage: ${usage}`);
|
|
1408
|
+
console.log(' --type is the WordPress post type, for example changelog or posts.\n');
|
|
1409
|
+
process.exit(1);
|
|
1410
|
+
}
|
|
1411
|
+
const objectFlag = (name) => {
|
|
1412
|
+
const v = jsonObjectFlag(flags[name]);
|
|
1413
|
+
if (v !== null) return v;
|
|
1414
|
+
console.log(`\n ✗ --${name} must be a JSON object, for example '{"changelog_product":[50]}'.\n`);
|
|
1415
|
+
process.exit(1);
|
|
1416
|
+
};
|
|
1417
|
+
const taxonomies = objectFlag('taxonomies');
|
|
1418
|
+
const acf = objectFlag('acf');
|
|
1419
|
+
|
|
1420
|
+
const doc = await authedCall(cfg, `/project/doc/${docId}`);
|
|
1421
|
+
if (!doc?.id) {
|
|
1422
|
+
console.error(`\n ✗ Document ${docId} not found (or no access).\n`);
|
|
1423
|
+
process.exit(1);
|
|
1424
|
+
}
|
|
1425
|
+
// The LIVE body, as `doc read` uses: the row's `content` is only written on a WordPress import.
|
|
1426
|
+
let live = null;
|
|
1427
|
+
try {
|
|
1428
|
+
live = await authedCall(cfg, `/project/doc/${docId}/content`);
|
|
1429
|
+
} catch {
|
|
1430
|
+
live = null;
|
|
1431
|
+
}
|
|
1432
|
+
const html = live?.html || doc.content || '';
|
|
1433
|
+
if (!html.trim()) {
|
|
1434
|
+
console.error('\n ✗ The document is empty, so there is nothing to draft on WordPress.\n');
|
|
1435
|
+
process.exit(1);
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
const result = await authedCall(cfg, `/project/doc/${docId}/wp/publish`, {
|
|
1439
|
+
html,
|
|
1440
|
+
title: doc.title,
|
|
1441
|
+
typePost: type,
|
|
1442
|
+
status: 'draft',
|
|
1443
|
+
...(typeof flags.slug === 'string' ? { slug: flags.slug } : {}),
|
|
1444
|
+
...(typeof flags.excerpt === 'string' ? { excerpt: flags.excerpt } : {}),
|
|
1445
|
+
...(taxonomies ? { taxonomies } : {}),
|
|
1446
|
+
...(acf ? { acf } : {}),
|
|
1447
|
+
});
|
|
1448
|
+
if (asJson) return console.log(JSON.stringify(result, null, 2));
|
|
1449
|
+
const postId = result?.wpPostId ?? result?.id ?? null;
|
|
1450
|
+
console.log(
|
|
1451
|
+
`\n \x1b[32m✓\x1b[0m WordPress draft${postId ? ` #${postId}` : ''} created and linked to document #${docId}.`,
|
|
1452
|
+
);
|
|
1453
|
+
console.log(' It is not live. Publish it from the document in Workover.\n');
|
|
1454
|
+
return;
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
if (sub === 'upload') {
|
|
1458
|
+
// Puts an image (a screenshot a scheduled job captured) into the document's media and prints the
|
|
1459
|
+
// markdown that places it. Nothing in the document changes until that markdown is written or
|
|
1460
|
+
// proposed, so this is safe to run unattended. Same route and guards as the MCP's upload tool.
|
|
1461
|
+
const usage = 'workover doc upload <doc> <image.png> [--alt "<text>"]';
|
|
1462
|
+
const docId = await resolveDocArg(cfg, positionals.slice(0, 1), usage);
|
|
1463
|
+
const file = positionals[1];
|
|
1464
|
+
if (!file) {
|
|
1465
|
+
console.log(`\n Usage: ${usage}\n`);
|
|
1466
|
+
process.exit(1);
|
|
1467
|
+
}
|
|
1468
|
+
let real;
|
|
1469
|
+
let size;
|
|
1470
|
+
try {
|
|
1471
|
+
real = realpathSync(file);
|
|
1472
|
+
size = statSync(real).size;
|
|
1473
|
+
} catch {
|
|
1474
|
+
console.error(`\n ✗ No file at ${file}.\n`);
|
|
1475
|
+
process.exit(1);
|
|
1476
|
+
}
|
|
1477
|
+
const vetted = vetImageUpload(real, size);
|
|
1478
|
+
if (vetted.error) {
|
|
1479
|
+
console.error(`\n ✗ ${vetted.error}\n`);
|
|
1480
|
+
process.exit(1);
|
|
1481
|
+
}
|
|
1482
|
+
const alt = typeof flags.alt === 'string' ? flags.alt : '';
|
|
1483
|
+
const form = new FormData();
|
|
1484
|
+
form.append('file', new Blob([readFileSync(real)], { type: vetted.mime }), real.split('/').pop());
|
|
1485
|
+
if (alt) form.append('alt', alt);
|
|
1486
|
+
const res = await fetch(`${cfg.api}/project/doc/${docId}/media`, {
|
|
1487
|
+
method: 'POST',
|
|
1488
|
+
headers: { authorization: `Bearer ${cfg.token}` },
|
|
1489
|
+
body: form,
|
|
1490
|
+
});
|
|
1491
|
+
if (!res.ok) {
|
|
1492
|
+
console.error(`\n ✗ Upload failed (${res.status}): ${(await res.text()).slice(0, 200)}\n`);
|
|
1493
|
+
process.exit(1);
|
|
1494
|
+
}
|
|
1495
|
+
const { url } = await res.json();
|
|
1496
|
+
if (asJson) return console.log(JSON.stringify({ url, alt, markdown: `` }, null, 2));
|
|
1497
|
+
console.log(``);
|
|
1498
|
+
return;
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1387
1501
|
if (sub === 'activity') {
|
|
1388
1502
|
const docId = await resolveDocArg(cfg, positionals, 'workover doc activity <doc>');
|
|
1389
1503
|
const limit = rowId(flags.limit) ?? 20;
|
package/lib.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Pure helpers for the Workover CLI, split out so they can be unit-tested without importing
|
|
2
2
|
// bin/workover.mjs (which runs a command + calls process.exit on load).
|
|
3
|
+
import { mkdirSync, writeFileSync, renameSync, chmodSync, rmSync } from 'fs';
|
|
4
|
+
import { dirname, join, basename } from 'path';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Strip trailing slashes from the API base URL (so `${API}${path}` never doubles up).
|
|
@@ -20,11 +22,52 @@ export const normalizeApi = (raw) => {
|
|
|
20
22
|
return s.slice(0, end);
|
|
21
23
|
};
|
|
22
24
|
|
|
23
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Map a platform + URL to the browser-open command used to approve the device login.
|
|
27
|
+
*
|
|
28
|
+
* Windows does NOT go through `cmd /c start`: cmd re-parses its command line, and Node only quotes
|
|
29
|
+
* arguments that contain spaces, so a URL holding `&` (every query string with two parameters) was
|
|
30
|
+
* split into a second command. `rundll32 url.dll,FileProtocolHandler` takes the URL as a plain
|
|
31
|
+
* argument with no shell in between. Only http(s) URLs are opened at all; anything else returns
|
|
32
|
+
* null and the caller just prints the URL.
|
|
33
|
+
*/
|
|
24
34
|
export const browserCommand = (platform, url) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
let parsed;
|
|
36
|
+
try {
|
|
37
|
+
parsed = new URL(url);
|
|
38
|
+
} catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') return null;
|
|
42
|
+
const href = parsed.href;
|
|
43
|
+
if (platform === 'darwin') return { cmd: 'open', args: [href] };
|
|
44
|
+
if (platform === 'win32') return { cmd: 'rundll32', args: ['url.dll,FileProtocolHandler', href] };
|
|
45
|
+
return { cmd: 'xdg-open', args: [href] };
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Write a file that holds a secret (the bearer token) so it is never readable by anyone else, not
|
|
50
|
+
* even for the moment between write and chmod: the directory is created 0700, the contents go to a
|
|
51
|
+
* temp file created 0600 in the same directory, and a rename swaps it in atomically. The chmod after
|
|
52
|
+
* covers a file that already existed with looser bits from an older CLI (rename keeps the temp
|
|
53
|
+
* file's mode, but an umask-free platform may still widen it).
|
|
54
|
+
*/
|
|
55
|
+
export const writePrivateFile = (file, contents) => {
|
|
56
|
+
const dir = dirname(file);
|
|
57
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
58
|
+
const tmp = join(dir, `.${basename(file)}.${process.pid}.${Date.now()}.tmp`);
|
|
59
|
+
try {
|
|
60
|
+
writeFileSync(tmp, contents, { mode: 0o600, flag: 'wx' });
|
|
61
|
+
renameSync(tmp, file);
|
|
62
|
+
} catch (err) {
|
|
63
|
+
rmSync(tmp, { force: true });
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
chmodSync(file, 0o600);
|
|
68
|
+
} catch {
|
|
69
|
+
/* Windows: POSIX modes are advisory */
|
|
70
|
+
}
|
|
28
71
|
};
|
|
29
72
|
|
|
30
73
|
/**
|
|
@@ -275,6 +318,17 @@ export const threadComments = (comments, { includeResolved = false } = {}) => {
|
|
|
275
318
|
const UUID_RE = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
|
|
276
319
|
const FULL_UUID_RE = new RegExp(`^${UUID_RE.source}$`, 'i');
|
|
277
320
|
|
|
321
|
+
/**
|
|
322
|
+
* `value` without any run of `chars` at its end. A loop rather than `/[…]+$/`: a regex anchored only
|
|
323
|
+
* at the end is retried from every position, which is quadratic on a long run of those characters
|
|
324
|
+
* that is not at the end (code scanning, js/polynomial-redos).
|
|
325
|
+
*/
|
|
326
|
+
const stripTrailing = (value, chars) => {
|
|
327
|
+
let end = value.length;
|
|
328
|
+
while (end > 0 && chars.includes(value[end - 1])) end -= 1;
|
|
329
|
+
return value.slice(0, end);
|
|
330
|
+
};
|
|
331
|
+
|
|
278
332
|
/**
|
|
279
333
|
* Which document somebody meant, from whatever they pasted.
|
|
280
334
|
*
|
|
@@ -294,10 +348,12 @@ const FULL_UUID_RE = new RegExp(`^${UUID_RE.source}$`, 'i');
|
|
|
294
348
|
*/
|
|
295
349
|
export const docRef = (value) => {
|
|
296
350
|
// Trim the wrapping that pasted links arrive in: <angle brackets>, quotes, a trailing full stop.
|
|
297
|
-
const s =
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
351
|
+
const s = stripTrailing(
|
|
352
|
+
String(value ?? '')
|
|
353
|
+
.trim()
|
|
354
|
+
.replace(/^[<"'([]+/, ''),
|
|
355
|
+
'>"\')].,;',
|
|
356
|
+
);
|
|
301
357
|
if (!s) return null;
|
|
302
358
|
const id = rowId(s);
|
|
303
359
|
if (id !== null) return { id };
|
|
@@ -423,3 +479,45 @@ export const signInHelp = (hint, configFile) =>
|
|
|
423
479
|
...(configFile ? [` The sign-in is saved to ${configFile}.`] : []),
|
|
424
480
|
'',
|
|
425
481
|
].join('\n');
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* A flag that carries a JSON object, such as `--taxonomies '{"changelog_product":[50]}'`.
|
|
485
|
+
*
|
|
486
|
+
* Returns `undefined` when the flag is absent, the object when it parses to one, and `null` when it
|
|
487
|
+
* is present but not a JSON object (an array, a number, or broken JSON), so the caller can say so
|
|
488
|
+
* rather than sending something the API would misread.
|
|
489
|
+
*/
|
|
490
|
+
export const jsonObjectFlag = (value) => {
|
|
491
|
+
if (value == null) return undefined;
|
|
492
|
+
try {
|
|
493
|
+
const v = JSON.parse(String(value));
|
|
494
|
+
return v && typeof v === 'object' && !Array.isArray(v) ? v : null;
|
|
495
|
+
} catch {
|
|
496
|
+
return null;
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
/** The image types the API's media upload accepts, and its size cap (apps/api multer config). */
|
|
501
|
+
export const UPLOAD_IMAGE_EXT = ['png', 'jpg', 'jpeg', 'gif', 'webp'];
|
|
502
|
+
export const UPLOAD_IMAGE_MAX_BYTES = 5 * 1024 * 1024;
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Whether `workover doc upload` may send a file. Takes the REAL path (symlinks already resolved, so a
|
|
506
|
+
* `shot.png` that points at a key is judged by its target) and its size. Refuses anything inside a dot
|
|
507
|
+
* file or dot directory (~/.ssh, ~/.workover), anything that is not an image type the API takes, and
|
|
508
|
+
* anything over the API's cap, so a scheduled agent cannot be talked into uploading a secret into a
|
|
509
|
+
* document the whole team can open. Returns `{ ext, mime }` or `{ error }`.
|
|
510
|
+
*/
|
|
511
|
+
export const vetImageUpload = (realPath, size) => {
|
|
512
|
+
const parts = String(realPath).split(/[\\/]/).filter(Boolean);
|
|
513
|
+
if (parts.some((part) => part.startsWith('.')))
|
|
514
|
+
return { error: 'Refusing a file inside a hidden (dot) file or directory.' };
|
|
515
|
+
const ext = (parts.at(-1) || '').split('.').pop().toLowerCase();
|
|
516
|
+
if (!UPLOAD_IMAGE_EXT.includes(ext))
|
|
517
|
+
return { error: `Only ${UPLOAD_IMAGE_EXT.join(', ')} images can be uploaded.` };
|
|
518
|
+
if (!(size > 0)) return { error: 'The file is empty.' };
|
|
519
|
+
if (size > UPLOAD_IMAGE_MAX_BYTES) return { error: 'The image is larger than 5 MB.' };
|
|
520
|
+
const mime = ext === 'jpg' || ext === 'jpeg' ? 'image/jpeg' : `image/${ext}`;
|
|
521
|
+
return { ext, mime };
|
|
522
|
+
};
|
|
523
|
+
|