Integrate graphics, RAW, audio and CAD Craft tools with protected saves
This commit is contained in:
1 parent
6e36b6c4b7
commit
852140c3a7
24 files changed
+600
-74
No files matched your search
@@ -1,13 +1,14 @@
|
||||
<template>
|
||||
<Action
|
||||
v-if="tool"
|
||||
v-for="tool in tools"
|
||||
:key="tool.id"
|
||||
icon="edit_note"
|
||||
:label="t('addons.openWith', { name: tool.name })"
|
||||
@action="openCraftTab(router, tool!.id, file!.url)"
|
||||
@action="openCraftTab(router, tool.id, file!.url)"
|
||||
/>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { openCraftTab } from "@/utils/craft";
|
||||
import { addonAccepts, openCraftTab } from "@/utils/craft";
|
||||
import { computed, onMounted } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { useI18n } from "vue-i18n";
|
||||
@@ -21,18 +22,16 @@ const store = useAddonsStore(),
|
||||
auth = useAuthStore(),
|
||||
router = useRouter(),
|
||||
{ t } = useI18n();
|
||||
const tool = computed(() =>
|
||||
const tools = computed(() =>
|
||||
props.file &&
|
||||
!props.file.isDir &&
|
||||
auth.user?.perm.download &&
|
||||
auth.user?.perm.modify
|
||||
? store.items.find(
|
||||
? store.items.filter(
|
||||
(item) =>
|
||||
item.enabled &&
|
||||
item.build &&
|
||||
props.file!.name.toLowerCase().endsWith(item.extension)
|
||||
item.enabled && item.build && addonAccepts(item, props.file!.name)
|
||||
)
|
||||
: undefined
|
||||
: []
|
||||
);
|
||||
onMounted(() => {
|
||||
store.refresh().catch(() => {});
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useAddonsStore } from "@/stores/addons";
|
||||
import { openCraftTab } from "@/utils/craft";
|
||||
import { addonAccepts, openCraftTab } from "@/utils/craft";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { useFileStore } from "@/stores/file";
|
||||
import { useLayoutStore } from "@/stores/layout";
|
||||
@@ -389,10 +389,7 @@ const open = () => {
|
||||
authStore.user?.perm.modify &&
|
||||
authStore.user?.perm.download
|
||||
? addons.items.find(
|
||||
(item) =>
|
||||
item.enabled &&
|
||||
item.build &&
|
||||
props.name.toLowerCase().endsWith(item.extension)
|
||||
(item) => item.enabled && item.build && addonAccepts(item, props.name)
|
||||
)
|
||||
: undefined;
|
||||
if (tool) {
|
||||
|
||||
@@ -6,22 +6,14 @@
|
||||
<div class="addon-grid">
|
||||
<article v-for="addon in store.items" :key="addon.id" class="addon-card">
|
||||
<div class="addon-details">
|
||||
<AppIcon
|
||||
:name="
|
||||
addon.id === 'gridcraft'
|
||||
? 'table'
|
||||
: addon.id === 'deckcraft'
|
||||
? 'slideshow'
|
||||
: addon.id === 'wordcraft'
|
||||
? 'editDocument'
|
||||
: 'description'
|
||||
"
|
||||
/>
|
||||
<AppIcon :name="addon.icon || 'package'" />
|
||||
<div>
|
||||
<strong>{{ addon.name }}</strong
|
||||
><small
|
||||
>{{ addon.version || t("addons.notInstalled") }} ·
|
||||
{{ addon.extension }}</small
|
||||
{{
|
||||
(addon.extensions || [addon.extension]).slice(0, 5).join(" · ")
|
||||
}}{{ (addon.extensions?.length || 0) > 5 ? " …" : "" }}</small
|
||||
><small v-if="busy(addon)"
|
||||
>{{ t("addons.states." + addon.state)
|
||||
}}<template v-if="addon.total">
|
||||
@@ -35,6 +27,9 @@
|
||||
}}</small>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="addon.id === 'lightcraft'" class="field-hint">
|
||||
{{ t("addons.rawCopies") }}
|
||||
</p>
|
||||
<div class="addon-controls">
|
||||
<label v-if="addon.build" class="settings-toggle"
|
||||
><span>{{ t("addons.enabled") }}</span
|
||||
|
||||
@@ -417,6 +417,7 @@
|
||||
"pdf": "PDF document"
|
||||
},
|
||||
"addons": {
|
||||
"rawCopies": "RAW originals stay unchanged. Exports are separate files; the library and adjustments live in this tab.",
|
||||
"popupBlocked": "Allow new tabs in your browser.",
|
||||
"title": "Addons",
|
||||
"description": "Editors run in your browser. Install official Artcraft releases with SHA-256 verification.",
|
||||
|
||||
@@ -414,6 +414,7 @@
|
||||
"pdf": "Документ PDF"
|
||||
},
|
||||
"addons": {
|
||||
"rawCopies": "RAW сохраняется без изменений. Экспорт — отдельным файлом; каталог и настройки обработки действуют в этой вкладке.",
|
||||
"popupBlocked": "Разрешите открытие новых вкладок в браузере.",
|
||||
"title": "Аддоны",
|
||||
"description": "Редакторы работают в браузере. Установка и обновление — из официальных релизов Artcraft с проверкой SHA-256.",
|
||||
|
||||
@@ -33,7 +33,7 @@ const titles = {
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: "/editor/:addon(wordcraft|gridcraft|deckcraft|pdfcraft)",
|
||||
path: "/editor/:addon(wordcraft|gridcraft|deckcraft|pdfcraft|photocraft|vectorcraft|lightcraft|designcraft|figcraft|soundcraft|cadcraft)",
|
||||
name: "CraftEditor",
|
||||
component: () => import("@/views/files/CraftEditor.vue"),
|
||||
meta: { requiresAuth: true },
|
||||
|
||||
@@ -4,6 +4,9 @@ export interface Addon {
|
||||
id: string;
|
||||
name: string;
|
||||
extension: string;
|
||||
extensions?: string[];
|
||||
exports?: string[];
|
||||
icon?: string;
|
||||
version: string;
|
||||
build: string;
|
||||
enabled: boolean;
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { craftLocation, craftMessage, safeCraftName } from "../craft";
|
||||
import {
|
||||
addonAccepts,
|
||||
craftSaveExtension,
|
||||
craftLocation,
|
||||
craftMessage,
|
||||
safeCraftName,
|
||||
} from "../craft";
|
||||
it("accepts messages only from the specific same-origin editor frame", () => {
|
||||
const frame = {} as Window,
|
||||
origin = "https://files.test";
|
||||
@@ -66,3 +72,15 @@ it("preserves encoded names in standalone editor links", () => {
|
||||
expect(location.query.path).toBe("/folder name/report #1%.xlsx");
|
||||
expect(location.params.addon).toBe("gridcraft");
|
||||
});
|
||||
|
||||
it("distinguishes editable outputs from import-only formats", () => {
|
||||
const raw = {
|
||||
extension: ".dng",
|
||||
extensions: [".dng", ".jpg"],
|
||||
exports: [".jpg", ".png"],
|
||||
} as import("@/stores/addons").Addon;
|
||||
expect(addonAccepts(raw, "PHOTO.DNG")).toBe(true);
|
||||
expect(craftSaveExtension(raw, "PHOTO.DNG")).toBeUndefined();
|
||||
expect(craftSaveExtension(raw, "edited.jpg")).toBe(".jpg");
|
||||
expect(addonAccepts(raw, "notes.txt")).toBe(false);
|
||||
});
|
||||
@@ -6,7 +6,7 @@ const source = readFileSync(
|
||||
new URL("../../../../http/craft_bridge.js", import.meta.url),
|
||||
"utf8"
|
||||
);
|
||||
function bridge(id = "wordcraft") {
|
||||
function bridge(id = "wordcraft", config?: Record<string, unknown>) {
|
||||
const messages: any[] = [],
|
||||
events = new Map<string, (event: any) => void>();
|
||||
const parent = { postMessage: (message: any) => messages.push(message) };
|
||||
@@ -27,6 +27,7 @@ function bridge(id = "wordcraft") {
|
||||
LocalURL.createObjectURL = () => "blob:test/" + ++counter;
|
||||
LocalURL.revokeObjectURL = vi.fn();
|
||||
const context: any = {
|
||||
__filebrowserCraft: config,
|
||||
parent,
|
||||
location: {
|
||||
pathname: `/addons/${id}/build/index.html`,
|
||||
@@ -145,3 +146,27 @@ it("captures presentation saves but preserves native downloads for unrelated exp
|
||||
link.click();
|
||||
expect(nativeClick).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("adapts verified graphics, layout, RAW and audio builds without changing office defaults", () => {
|
||||
for (const [id, extension, output] of [
|
||||
["photocraft", ".png", ".pcraft"],
|
||||
["designcraft", ".designcraft", ".designcraft"],
|
||||
["figcraft", ".figcraft", ".figcraft"],
|
||||
["lightcraft", ".dng", ".jpg"],
|
||||
["soundcraft", ".wav", ".scraftz"],
|
||||
]) {
|
||||
const { receive, canvas, messages } = bridge(id, {
|
||||
id,
|
||||
extension,
|
||||
extensions: [extension],
|
||||
exports: [output],
|
||||
});
|
||||
expect(messages[0].type).toBe(id + ":ready");
|
||||
receive({
|
||||
type: id + ":open",
|
||||
name: "source" + extension,
|
||||
bytes: new ArrayBuffer(8),
|
||||
});
|
||||
expect(canvas.dispatchEvent).toHaveBeenCalledTimes(1);
|
||||
}
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { Addon } from "@/stores/addons";
|
||||
import type { Router } from "vue-router";
|
||||
|
||||
export function craftLocation(id: string, fileURL: string) {
|
||||
@@ -54,3 +55,18 @@ export function craftMessage(
|
||||
error?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export function addonAccepts(addon: Addon, name: string) {
|
||||
return (addon.extensions || [addon.extension]).some((extension) =>
|
||||
name.toLowerCase().endsWith(extension)
|
||||
);
|
||||
}
|
||||
export function craftSaveExtension(
|
||||
addon: Addon,
|
||||
name: unknown
|
||||
): string | undefined {
|
||||
if (typeof name !== "string") return undefined;
|
||||
return (addon.exports || [addon.extension, ".pdf"]).find((extension) =>
|
||||
name.toLowerCase().endsWith(extension)
|
||||
);
|
||||
}
|
||||
@@ -77,9 +77,19 @@ const currentView = computed(() => {
|
||||
return FileListing;
|
||||
}
|
||||
if (
|
||||
["wordcraft", "gridcraft", "deckcraft", "pdfcraft"].includes(
|
||||
String(route.query.craft)
|
||||
)
|
||||
[
|
||||
"wordcraft",
|
||||
"gridcraft",
|
||||
"deckcraft",
|
||||
"pdfcraft",
|
||||
"photocraft",
|
||||
"vectorcraft",
|
||||
"lightcraft",
|
||||
"designcraft",
|
||||
"figcraft",
|
||||
"soundcraft",
|
||||
"cadcraft",
|
||||
].includes(String(route.query.craft))
|
||||
)
|
||||
return CraftEditor;
|
||||
if (
|
||||
|
||||
@@ -85,7 +85,12 @@ import { useAuthStore } from "@/stores/auth";
|
||||
import { useAddonsStore } from "@/stores/addons";
|
||||
import { baseURL } from "@/utils/constants";
|
||||
import { fetchURL, StatusError } from "@/api/utils";
|
||||
import { craftMessage, safeCraftName } from "@/utils/craft";
|
||||
import {
|
||||
addonAccepts,
|
||||
craftSaveExtension,
|
||||
craftMessage,
|
||||
safeCraftName,
|
||||
} from "@/utils/craft";
|
||||
const route = useRoute(),
|
||||
store = useAddonsStore(),
|
||||
files = useFileStore(),
|
||||
@@ -99,9 +104,7 @@ const file = files.req,
|
||||
: file?.path || "";
|
||||
const currentPath = ref(sourcePath),
|
||||
currentName = ref(sourcePath.split("/").pop() || "");
|
||||
const nativeExtension = computed(
|
||||
() => store.items.find((item) => item.id === id)?.extension || ""
|
||||
);
|
||||
const activeTool = computed(() => store.items.find((item) => item.id === id));
|
||||
const title = computed(
|
||||
() => store.items.find((item) => item.id === id)?.name || id
|
||||
);
|
||||
@@ -214,7 +217,11 @@ async function persist() {
|
||||
window.location.origin
|
||||
);
|
||||
authExpired.value = false;
|
||||
if (payload.path.toLowerCase().endsWith(nativeExtension.value)) {
|
||||
if (
|
||||
id !== "lightcraft" &&
|
||||
activeTool.value &&
|
||||
addonAccepts(activeTool.value, payload.name)
|
||||
) {
|
||||
tag = response.headers.get("ETag") || "";
|
||||
currentPath.value = payload.path;
|
||||
currentName.value = payload.name;
|
||||
@@ -247,9 +254,10 @@ async function persist() {
|
||||
}
|
||||
function confirmSaveAs() {
|
||||
if (!pending.value) return;
|
||||
const ext = pending.value.name.toLowerCase().endsWith(".pdf")
|
||||
? ".pdf"
|
||||
: nativeExtension.value;
|
||||
const ext =
|
||||
activeTool.value &&
|
||||
craftSaveExtension(activeTool.value, pending.value.name);
|
||||
if (!ext) return;
|
||||
const name = safeCraftName(newName.value, ext);
|
||||
if (!name) {
|
||||
error.value = t("addons.invalidName");
|
||||
@@ -307,15 +315,21 @@ function receive(event: MessageEvent) {
|
||||
error.value = t("addons.tooLarge");
|
||||
return;
|
||||
}
|
||||
const extension = message.name?.toLowerCase().endsWith(".pdf")
|
||||
? ".pdf"
|
||||
: nativeExtension.value;
|
||||
const name = safeCraftName(message.name, extension);
|
||||
const extension =
|
||||
activeTool.value && craftSaveExtension(activeTool.value, message.name);
|
||||
if (!extension) {
|
||||
error.value = t("addons.invalidName");
|
||||
return;
|
||||
}
|
||||
let name = safeCraftName(message.name, extension);
|
||||
if (!name) {
|
||||
error.value = t("addons.invalidName");
|
||||
return;
|
||||
}
|
||||
const create = !!message.saveAs || name !== currentName.value;
|
||||
if (id === "lightcraft" && name === currentName.value)
|
||||
name = name.slice(0, -extension.length) + "-edited" + extension;
|
||||
const create =
|
||||
id === "lightcraft" || !!message.saveAs || name !== currentName.value;
|
||||
pending.value = {
|
||||
bytes: message.bytes,
|
||||
name,
|
||||
@@ -346,7 +360,7 @@ onMounted(async () => {
|
||||
!addon ||
|
||||
!auth.user?.perm.modify ||
|
||||
!auth.user?.perm.download ||
|
||||
!sourcePath.toLowerCase().endsWith(addon.extension)
|
||||
!addonAccepts(addon, sourcePath)
|
||||
)
|
||||
throw new Error(t("addons.unavailable"));
|
||||
// Bound streamed data even when Content-Length is missing.
|
||||
@@ -387,7 +401,9 @@ onMounted(async () => {
|
||||
id +
|
||||
"/" +
|
||||
addon.build +
|
||||
"/index.html?host=parent&author=" +
|
||||
"/index.html?host=parent" +
|
||||
(id === "lightcraft" ? "&store=memory" : "") +
|
||||
"&author=" +
|
||||
encodeURIComponent(auth.user.profileName || auth.user.username);
|
||||
startup = setTimeout(() => {
|
||||
error.value = t("addons.startFailed");
|
||||
|
||||
Reference in new issue
Block a user