fix(uploads): patch endpoint-media scope handling
This commit is contained in:
@@ -61,4 +61,6 @@
|
|||||||
## Startup script
|
## Startup script
|
||||||
|
|
||||||
- `start.sh` is intentionally ignored by Git (`.gitignore`) so server secrets are not committed.
|
- `start.sh` is intentionally ignored by Git (`.gitignore`) so server secrets are not committed.
|
||||||
- Use `start.example.sh` as the tracked template and keep real credentials in environment variables (or `.env` on the server).
|
- Use `start.example.sh` as the tracked template and keep real credentials in environment variables (or `.env` on the server).
|
||||||
|
- Startup scripts run patch helpers before boot (`scripts/patch-lightningcss.mjs`, `scripts/patch-endpoint-media-scope.mjs`).
|
||||||
|
- The media scope patch fixes a known upstream issue where file uploads can fail if the token scope is `create update delete` without explicit `media`.
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postinstall": "node scripts/patch-lightningcss.mjs",
|
"postinstall": "node scripts/patch-lightningcss.mjs && node scripts/patch-endpoint-media-scope.mjs",
|
||||||
"serve": "node node_modules/@indiekit/indiekit/bin/cli.js serve --config indiekit.config.mjs",
|
"serve": "node scripts/patch-lightningcss.mjs && node scripts/patch-endpoint-media-scope.mjs && node node_modules/@indiekit/indiekit/bin/cli.js serve --config indiekit.config.mjs",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
|
|||||||
51
scripts/patch-endpoint-media-scope.mjs
Normal file
51
scripts/patch-endpoint-media-scope.mjs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { access, readFile, writeFile } from "node:fs/promises";
|
||||||
|
|
||||||
|
const candidates = [
|
||||||
|
"node_modules/@indiekit/endpoint-media/lib/scope.js",
|
||||||
|
"node_modules/@indiekit/indiekit/node_modules/@indiekit/endpoint-media/lib/scope.js",
|
||||||
|
];
|
||||||
|
|
||||||
|
const oldCode = 'if (scope === "create" && action === "media") {';
|
||||||
|
const newCode = 'if (scope.includes("create") && action === "media") {';
|
||||||
|
|
||||||
|
async function exists(path) {
|
||||||
|
try {
|
||||||
|
await access(path);
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let checked = 0;
|
||||||
|
let patched = 0;
|
||||||
|
|
||||||
|
for (const filePath of candidates) {
|
||||||
|
if (!(await exists(filePath))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
checked += 1;
|
||||||
|
|
||||||
|
const source = await readFile(filePath, "utf8");
|
||||||
|
|
||||||
|
if (source.includes(newCode)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!source.includes(oldCode)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const updated = source.replace(oldCode, newCode);
|
||||||
|
await writeFile(filePath, updated, "utf8");
|
||||||
|
patched += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checked === 0) {
|
||||||
|
console.log("[postinstall] No endpoint-media scope files found");
|
||||||
|
} else if (patched === 0) {
|
||||||
|
console.log("[postinstall] endpoint-media scope already patched");
|
||||||
|
} else {
|
||||||
|
console.log(`[postinstall] Patched endpoint-media scope in ${patched} file(s)`);
|
||||||
|
}
|
||||||
@@ -27,4 +27,8 @@ fi
|
|||||||
|
|
||||||
export NODE_ENV="${NODE_ENV:-production}"
|
export NODE_ENV="${NODE_ENV:-production}"
|
||||||
|
|
||||||
|
# Ensure runtime dependency patches are applied even if node_modules already exists.
|
||||||
|
/usr/local/bin/node scripts/patch-lightningcss.mjs
|
||||||
|
/usr/local/bin/node scripts/patch-endpoint-media-scope.mjs
|
||||||
|
|
||||||
exec /usr/local/bin/node node_modules/@indiekit/indiekit/bin/cli.js serve --config indiekit.config.mjs
|
exec /usr/local/bin/node node_modules/@indiekit/indiekit/bin/cli.js serve --config indiekit.config.mjs
|
||||||
|
|||||||
Reference in New Issue
Block a user