From 05b757fb76f7232a784db9f6ac6982a372111b12 Mon Sep 17 00:00:00 2001 From: Bruno Perel Date: Sun, 26 Jan 2025 16:33:27 +0100 Subject: [PATCH] edgecreator,edgecreator-api: Fix edges path, fix username retrieval during image upload --- apps/edgecreator/api/.env | 2 +- apps/edgecreator/api/index.ts | 4 ++++ apps/edgecreator/api/services/browse/index.ts | 8 +++----- apps/edgecreator/api/services/upload/index.ts | 5 ++--- apps/edgecreator/src/pages/upload.vue | 4 ++-- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/apps/edgecreator/api/.env b/apps/edgecreator/api/.env index b53ffc84..de4db500 100644 --- a/apps/edgecreator/api/.env +++ b/apps/edgecreator/api/.env @@ -5,7 +5,7 @@ FONT_PRODUCT_BASE_URL=https://www.myfonts.com/products/ TOKEN_SECRET=3543c30fe79047b4f73cfb61aa1eb52cb3173de4b3941e0fc4ec1b127bbeed6019695a1a453a81c33c2eea964ccc577e69c7df994124bd2751e262a311ea23a1 -EDGES_PATH=../edges +EDGES_PATH=../../edges DM_SOCKET_URL=http://localhost:3000 diff --git a/apps/edgecreator/api/index.ts b/apps/edgecreator/api/index.ts index 95df8e7f..17e380cd 100644 --- a/apps/edgecreator/api/index.ts +++ b/apps/edgecreator/api/index.ts @@ -23,6 +23,10 @@ import uploadServices, { upload } from "./services/upload"; const port = 3001; +export const getEdgesPath = () => process.env.EDGES_PATH!.startsWith("/") + ? process.env.EDGES_PATH! + : `${import.meta.dirname}/../../${process.env.EDGES_PATH!}`; + class ServerWithUser extends Server< Record, Record, diff --git a/apps/edgecreator/api/services/browse/index.ts b/apps/edgecreator/api/services/browse/index.ts index fc8d37c9..c532cedb 100644 --- a/apps/edgecreator/api/services/browse/index.ts +++ b/apps/edgecreator/api/services/browse/index.ts @@ -8,6 +8,7 @@ import { prismaClient as prismaCoa } from "~prisma-schemas/schemas/coa/client"; import type Events from "./types"; import type { EdgeModelDetails } from "./types"; import { namespaceEndpoint } from "./types"; +import { getEdgesPath } from "~/index"; const parser = new XMLParser({ ignoreAttributes: false, @@ -81,14 +82,11 @@ const findInDir = (dir: string) => }); export default (io: Server) => { - const edgesPath = process.env.EDGES_PATH!.startsWith("/") - ? process.env.EDGES_PATH! - : `${process.env.PWD!}/../${process.env.EDGES_PATH!}`; (io.of(namespaceEndpoint) as Namespace).on("connection", (socket) => { console.log("connected to browse"); socket.on("listEdgeModels", async (callback) => { - findInDir(edgesPath) + findInDir(getEdgesPath()) .then((results) => { callback({ results }); }) @@ -112,7 +110,7 @@ export default (io: Server) => { try { callback({ results: readdirSync( - `${process.env.EDGES_PATH!}/${country}/${imageType}`, + `${getEdgesPath()}/${country}/${imageType}`, ).filter((item) => new RegExp(`(?:^|[. ])${magazine}(?:[. ]|$)`).test(item), ), diff --git a/apps/edgecreator/api/services/upload/index.ts b/apps/edgecreator/api/services/upload/index.ts index 68b223cb..3f286518 100644 --- a/apps/edgecreator/api/services/upload/index.ts +++ b/apps/edgecreator/api/services/upload/index.ts @@ -13,8 +13,7 @@ import { SocketClient } from "~socket.io-client-services"; import { getNextAvailableFile } from "../_upload_utils"; import type Events from "./types"; import { namespaceEndpoint } from "./types"; - -const getEdgesPath = () => process.env.EDGES_PATH!; +import { getEdgesPath } from "~/index"; let edgeCreatorServices: EventCalls; @@ -111,7 +110,7 @@ export const upload = async ( await storePhotoHash(targetFilename, hash); targetFilesnames.push( targetFilename.replace( - process.env.EDGES_PATH!, + getEdgesPath(), process.env.VITE_EDGES_URL!, ), ); diff --git a/apps/edgecreator/src/pages/upload.vue b/apps/edgecreator/src/pages/upload.vue index e3ed837d..6a2656d6 100644 --- a/apps/edgecreator/src/pages/upload.vue +++ b/apps/edgecreator/src/pages/upload.vue @@ -195,10 +195,10 @@ const uploadedImageData = ref<{ url: string } | null>(null); const cropper = ref(null); const initialContributors = computed( - (): Omit[] => [ + (): Omit[] => !collection().user ? []:[ { contributionType: "photographe", - user: { id: 0, username: useCookies().get("dm-user") }, + user: { id: collection().user!.id, username: collection().user!.username }, }, ] );