Skip to content

Commit

Permalink
edgecreator-api: Fix issue retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
bperel committed Jan 26, 2025
1 parent e42b3d7 commit e09cb2d
Showing 1 changed file with 36 additions and 35 deletions.
71 changes: 36 additions & 35 deletions apps/edgecreator/api/services/browse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const REGEX_IS_SVG_FILE = /^_?.+\.svg$/;

const getSvgMetadata = (
metadataNodes: { "#text": string; type?: string }[],
metadataType: string,
metadataType: string
) =>
metadataNodes
.filter(({ type }) => type === metadataType)
Expand All @@ -37,44 +37,45 @@ const findInDir = (dir: string) =>
current: [],
published: [],
};
const filteredFiles = readdirSync(dir, {
recursive: true,
withFileTypes: true,
}).filter((file) => REGEX_IS_SVG_FILE.test(file.name));
for (const file of filteredFiles) {
const filePath = path.join(file.parentPath, file.name);
const filename = filePath.replace(/.+\/edges\//, "");
const [countrycode, magazinecodeAndIssuenumber] =
filename.split("/gen/");
const [magazinecode, issuenumberShort] =
magazinecodeAndIssuenumber.split(".");
const publicationcode = `${countrycode}/${magazinecode}`;
const [{ issuecode }] = await prismaCoa.$queryRaw<
{ issuecode: string }[]
>`
const filteredFiles = readdirSync(dir, {
recursive: true,
withFileTypes: true,
}).filter((file) => REGEX_IS_SVG_FILE.test(file.name));
for (const file of filteredFiles) {
const filePath = path.join(file.parentPath, file.name);
const filename = filePath.replace(/.+\/edges\//, "");
const [countrycode, magazinecodeAndIssuenumber] = filename.split("/gen/");
const [magazinecode, issuenumberShort] =
magazinecodeAndIssuenumber.split(".");
const publicationcode = `${countrycode}/${magazinecode}`;
const [issue] = await prismaCoa.$queryRaw<{ issuecode: string }[]>`
SELECT issuecode
FROM inducks_issue
WHERE publicationcode = ${publicationcode}
AND REPLACE(issuenumber, ' ', '') = ${issuenumberShort}`;
const edgeStatus = file.name.startsWith("_") ? "current" : "published";
if (!issue) {
console.log(`${publicationcode}/${issuenumberShort} not found`);
continue;
}
const edgeStatus = file.name.startsWith("_") ? "current" : "published";

const doc = parser.parse(readFileSync(filePath));
const metadataNodes = doc.svg.metadata;
const doc = parser.parse(readFileSync(filePath));
const metadataNodes = doc.svg.metadata;

const designers = getSvgMetadata(metadataNodes, "contributor-designer");
const photographers = getSvgMetadata(
metadataNodes,
"contributor-photographer",
);
const designers = getSvgMetadata(metadataNodes, "contributor-designer");
const photographers = getSvgMetadata(
metadataNodes,
"contributor-photographer"
);

fileList[edgeStatus].push({
issuecode,
url: `${process.env.EDGES_URL!}/${filePath}`,
designers,
photographers,
});
}
resolve(fileList);
fileList[edgeStatus].push({
issuecode: issue.issuecode,
url: `${process.env.EDGES_URL!}/${filePath}`,
designers,
photographers,
});
}
resolve(fileList);
});

export default (io: Server) => {
Expand All @@ -90,7 +91,7 @@ export default (io: Server) => {
callback({
error: "Generic error",
errorDetails: errorDetails as string,
}),
})
);
});

Expand All @@ -106,9 +107,9 @@ export default (io: Server) => {
try {
callback({
results: readdirSync(
`${getEdgesPath()}/${country}/${imageType}`,
`${getEdgesPath()}/${country}/${imageType}`
).filter((item) =>
new RegExp(`(?:^|[. ])${magazine}(?:[. ]|$)`).test(item),
new RegExp(`(?:^|[. ])${magazine}(?:[. ]|$)`).test(item)
),
});
} catch (_e) {
Expand Down

0 comments on commit e09cb2d

Please sign in to comment.