Skip to content

Commit

Permalink
edgecreator,edgecreator-api: Fix edges path, fix username retrieval d…
Browse files Browse the repository at this point in the history
…uring image upload
  • Loading branch information
bperel committed Jan 26, 2025
1 parent a8dac1c commit 05b757f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion apps/edgecreator/api/.env
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions apps/edgecreator/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, never>,
Record<string, never>,
Expand Down
8 changes: 3 additions & 5 deletions apps/edgecreator/api/services/browse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Events>).on("connection", (socket) => {
console.log("connected to browse");

socket.on("listEdgeModels", async (callback) => {
findInDir(edgesPath)
findInDir(getEdgesPath())
.then((results) => {
callback({ results });
})
Expand All @@ -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),
),
Expand Down
5 changes: 2 additions & 3 deletions apps/edgecreator/api/services/upload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<EdgeCreatorServices>;

Expand Down Expand Up @@ -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!,
),
);
Expand Down
4 changes: 2 additions & 2 deletions apps/edgecreator/src/pages/upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ const uploadedImageData = ref<{ url: string } | null>(null);
const cropper = ref<Cropper | null>(null);
const initialContributors = computed(
(): Omit<ModelContributor, "issuecode">[] => [
(): Omit<ModelContributor, "issuecode">[] => !collection().user ? []:[
{
contributionType: "photographe",
user: { id: 0, username: useCookies().get("dm-user") },
user: { id: collection().user!.id, username: collection().user!.username },
},
]
);
Expand Down

0 comments on commit 05b757f

Please sign in to comment.