simplify workshop submission storage
This commit is contained in:
1 parent
6f957ee984
commit
98d56264da
22 files changed
+52
-29625
No files matched your search
@@ -18,7 +18,6 @@
|
||||
"./schema": "./src/schema.ts"
|
||||
},
|
||||
"scripts": {
|
||||
"build:pocketbase-validator": "node ../../scripts/build-workshop-validator.mjs",
|
||||
"clean": "rm -rf .turbo node_modules",
|
||||
"format": "oxfmt .",
|
||||
"lint": "oxlint",
|
||||
@@ -35,7 +34,6 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@homarr/tsconfig": "workspace:^0.1.0",
|
||||
"esbuild": "catalog:",
|
||||
"typescript": "catalog:",
|
||||
"vitest": "catalog:"
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
WORKSHOP_API_URL,
|
||||
MAX_WORKSHOP_SCREENSHOTS,
|
||||
WORKSHOP_REQUEST_TIMEOUT_MS,
|
||||
WORKSHOP_SCHEMA_BY_TYPE,
|
||||
workshopCommentSchema,
|
||||
workshopReportSchema,
|
||||
workshopSubmissionDetailSchema,
|
||||
@@ -437,6 +438,7 @@ export class WorkshopBackend {
|
||||
const data = new FormData();
|
||||
Object.entries(parsed).forEach(([key, value]) => data.set(key, typeof value === "string" ? value : String(value)));
|
||||
data.set("author", this.currentUser?.id ?? "");
|
||||
data.set("widgetSchema", WORKSHOP_SCHEMA_BY_TYPE[parsed.type]);
|
||||
screenshots.forEach((file) => data.append("screenshots", file));
|
||||
try {
|
||||
const result = await this.pocketBase.collection("submissions").create(data);
|
||||
|
||||
@@ -96,7 +96,7 @@ describe("WorkshopBackend", () => {
|
||||
expect(mocks.autoCancellation).toHaveBeenCalledWith(false);
|
||||
});
|
||||
|
||||
test("leaves schema and initial revision ownership to PocketBase", async () => {
|
||||
test("sends the exported schema while leaving initial revision ownership to PocketBase", async () => {
|
||||
const client = new WorkshopBackend("https://workshop.example.com");
|
||||
client.pocketBase.authStore.save("token", { id: "author-id" } as never);
|
||||
mocks.create.mockResolvedValue({ id: "submission-id" });
|
||||
@@ -113,7 +113,7 @@ describe("WorkshopBackend", () => {
|
||||
|
||||
const payload = mocks.create.mock.calls[0]?.[0] as FormData;
|
||||
expect(payload.get("author")).toBe("author-id");
|
||||
expect(payload.get("widgetSchema")).toBeNull();
|
||||
expect(payload.get("widgetSchema")).toBe("homarr-custom-css-v1");
|
||||
expect(payload.get("revision")).toBeNull();
|
||||
});
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
import { customWidgetDefinitionSchema } from "@homarr/custom-widgets/core";
|
||||
|
||||
import { installPocketBaseUrlPolyfill } from "./pocketbase-url";
|
||||
|
||||
installPocketBaseUrlPolyfill();
|
||||
|
||||
export type PocketBaseWidgetValidationResult = { success: true; content: string } | { success: false; error: string };
|
||||
|
||||
/**
|
||||
* PocketBase loads the generated CommonJS bundle of this module in its
|
||||
* embedded JSVM. Keeping the canonical schema here prevents direct Workshop
|
||||
* writes from accepting definitions that Homarr would reject at install time.
|
||||
*/
|
||||
export function validatePocketBaseWidget(content: string): PocketBaseWidgetValidationResult {
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(content) as unknown;
|
||||
} catch {
|
||||
return { success: false, error: "Widget content must be valid JSON" };
|
||||
}
|
||||
|
||||
const result = customWidgetDefinitionSchema.safeParse(parsed);
|
||||
if (!result.success) {
|
||||
return {
|
||||
success: false,
|
||||
error:
|
||||
result.error.issues
|
||||
.slice(0, 5)
|
||||
.map((issue) => `${issue.path.join(".") || "widget"}: ${issue.message}`)
|
||||
.join("\n") || "Invalid widget",
|
||||
};
|
||||
}
|
||||
|
||||
return { success: true, content: JSON.stringify(result.data) };
|
||||
}
|
||||
@@ -74,7 +74,7 @@ describe("Workshop widget validation", () => {
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test("uses canonical direct-binding validation before publication", () => {
|
||||
test("validates direct bindings in the official client before publication", () => {
|
||||
const widget = {
|
||||
...CUSTOM_WIDGET_STARTER,
|
||||
requests: {
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import { customWidgetImportSchema } from "@homarr/custom-widgets/core";
|
||||
import { CUSTOM_WIDGET_SCHEMA, customWidgetImportSchema } from "@homarr/custom-widgets/core";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
export const HOMARR_WEBSITE_URL = "https://homarr.dev";
|
||||
export const WORKSHOP_API_URL = HOMARR_WEBSITE_URL;
|
||||
export const WORKSHOP_WEB_URL = `${HOMARR_WEBSITE_URL}/workshop`;
|
||||
export const WORKSHOP_CSS_SCHEMA = "homarr-custom-css-v1";
|
||||
export const WORKSHOP_SCHEMA_BY_TYPE = {
|
||||
customWidget: CUSTOM_WIDGET_SCHEMA,
|
||||
customCss: WORKSHOP_CSS_SCHEMA,
|
||||
} as const;
|
||||
export const MAX_WORKSHOP_CSS_LENGTH = 16_384;
|
||||
export const MAX_WORKSHOP_CONTENT_LENGTH = 1_000_000;
|
||||
export const MAX_WORKSHOP_SCREENSHOTS = 5;
|
||||
|
||||
Reference in new issue
Block a user