mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-05 10:01:27 +08:00
fix(protocol): 同步公开插件分享的图标字段
Signed-off-by: liugaowei <liugaowei@xd.com>
This commit is contained in:
@@ -26,6 +26,19 @@ describe("public plugin presentation boundary", () => {
|
||||
}),
|
||||
).toEqual(publicView);
|
||||
});
|
||||
it("preserves an embedded current plugin icon without exposing its storage location", () => {
|
||||
const icon = "data:image/png;base64,iVBORw0KGgo=";
|
||||
expect(parsePublicPluginPresentation({ ...publicView, icon })).toEqual({ ...publicView, icon });
|
||||
expect(parsePublicPluginPresentation({ ...publicView, icon: null }).icon).toBeNull();
|
||||
});
|
||||
it.each([
|
||||
"https://example.test/icon.png",
|
||||
"data:image/svg+xml;base64,PHN2Zz48L3N2Zz4=",
|
||||
"data:image/png;base64,invalid!",
|
||||
`data:image/png;base64,${"A".repeat(700_000)}`,
|
||||
])("uses the missing-icon state for an unsafe or oversized image", (icon) => {
|
||||
expect(parsePublicPluginPresentation({ ...publicView, icon }).icon).toBeNull();
|
||||
});
|
||||
it.each([
|
||||
{ schemaVersion: 2 },
|
||||
{ pluginId: "../../private" },
|
||||
|
||||
@@ -15,6 +15,8 @@ export interface PublicPluginPresentation {
|
||||
author: string | null;
|
||||
version: string;
|
||||
publishedAt: string;
|
||||
/** Current verified raster icon, embedded without a storage URL; absent on older servers. */
|
||||
icon?: string | null;
|
||||
}
|
||||
|
||||
export function parsePublicPluginPresentation(
|
||||
@@ -26,6 +28,11 @@ export function parsePublicPluginPresentation(
|
||||
}
|
||||
const nullableText = (value: unknown, path: string, max: number) =>
|
||||
value === null || value === "" ? null : string(value, path, max);
|
||||
const image = typeof row.icon === "string" && row.icon.length <= Math.ceil(512 * 1024 / 3) * 4 + 32
|
||||
? /^data:image\/(png|jpeg|webp|gif);base64,([A-Za-z0-9+/]+={0,2})$/.exec(row.icon) : null;
|
||||
const base64 = image?.[2] ?? "";
|
||||
const size = base64.length / 4 * 3 - (base64.endsWith("==") ? 2 : base64.endsWith("=") ? 1 : 0);
|
||||
const icon = image && base64.length % 4 === 0 && size <= 512 * 1024 ? row.icon as string : null;
|
||||
return {
|
||||
schemaVersion: 1,
|
||||
pluginId: row.pluginId,
|
||||
@@ -34,5 +41,6 @@ export function parsePublicPluginPresentation(
|
||||
author: nullableText(row.author, "author", 256),
|
||||
version: string(row.version, "version", 128),
|
||||
publishedAt: isoDate(row.publishedAt, "publishedAt"),
|
||||
...(row.icon === undefined ? {} : { icon }),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user