mirror of
https://github.com/imgfloat/server.git
synced 2026-02-05 03:39:26 +00:00
Update placeholder and validation
This commit is contained in:
0
src/main/resources/static/js/broadcastRuntime.js
Normal file
0
src/main/resources/static/js/broadcastRuntime.js
Normal file
2
src/main/resources/static/js/broadcastWorkers.js
Normal file
2
src/main/resources/static/js/broadcastWorkers.js
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
function spawnUserJavaScriptWorker(jsSource, data) {
|
||||||
|
}
|
||||||
@@ -43,12 +43,42 @@ function getUserJavaScriptSourceError(src) {
|
|||||||
return { title: "Syntax Error", details: e.message };
|
return { title: "Syntax Error", details: e.message };
|
||||||
}
|
}
|
||||||
|
|
||||||
const functionNames = ast.body.filter((node) => node.type === "FunctionDeclaration").map((node) => node.id.name);
|
let hasInit = false;
|
||||||
if (!functionNames.includes("init")) {
|
let hasTick = false;
|
||||||
return { title: "Missing function: init", details: "Your code must include a function named 'init'." };
|
|
||||||
|
for (const node of ast.body) {
|
||||||
|
if (node.type !== "ExpressionStatement") continue;
|
||||||
|
|
||||||
|
const expr = node.expression;
|
||||||
|
if (expr.type !== "AssignmentExpression") continue;
|
||||||
|
|
||||||
|
const left = expr.left;
|
||||||
|
const right = expr.right;
|
||||||
|
|
||||||
|
if (
|
||||||
|
left.type === "MemberExpression" &&
|
||||||
|
left.object.type === "Identifier" &&
|
||||||
|
left.object.name === "exports" &&
|
||||||
|
left.property.type === "Identifier" &&
|
||||||
|
(right.type === "FunctionExpression" || right.type === "ArrowFunctionExpression")
|
||||||
|
) {
|
||||||
|
if (left.property.name === "init") hasInit = true;
|
||||||
|
if (left.property.name === "tick") hasTick = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!functionNames.includes("tick")) {
|
|
||||||
return { title: "Missing function: tick", details: "Your code must include a function named 'tick'." };
|
if (!hasInit) {
|
||||||
|
return {
|
||||||
|
title: "Missing function: init",
|
||||||
|
details: "You must assign a function to exports.init",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasTick) {
|
||||||
|
return {
|
||||||
|
title: "Missing function: tick",
|
||||||
|
details: "You must assign a function to exports.tick",
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|||||||
@@ -392,7 +392,7 @@
|
|||||||
<textarea
|
<textarea
|
||||||
class="text-input"
|
class="text-input"
|
||||||
id="custom-asset-code"
|
id="custom-asset-code"
|
||||||
placeholder="function init({ surface, assets, channel }) { } function tick() { }"
|
placeholder="exports.init = ({ surface, assets, channel }) => { }; exports.tick = () => { };"
|
||||||
rows="25"
|
rows="25"
|
||||||
required
|
required
|
||||||
></textarea>
|
></textarea>
|
||||||
|
|||||||
Reference in New Issue
Block a user