ref: backend
This commit is contained in:
@@ -34,6 +34,11 @@ router.post("/characters", (req, res, next) => __awaiter(void 0, void 0, void 0,
|
||||
yield (0, svg_1.createCharacterDirectory)(userDir, characterName);
|
||||
// Generate a unique filename for the SVG
|
||||
const svgPath = yield (0, svg_1.generateUniqueSVGPath)(`${userDir}/${characterName}`);
|
||||
if (svgPath === "ERROR_NO_CHARACTER_DIRECTORY") {
|
||||
return res
|
||||
.status(404)
|
||||
.json({ error: "Character directory does not exist" });
|
||||
}
|
||||
// Extract the SVG content from the data URL
|
||||
const svgContent = decodeURIComponent(svg.split(",")[1]);
|
||||
// Write the SVG content to a file
|
||||
@@ -87,9 +92,17 @@ router.post("/handwriting", (req, res, next) => __awaiter(void 0, void 0, void 0
|
||||
.json({ error: `Missing character/s ${totalMissing.join(",")}` });
|
||||
}
|
||||
// Generate a larger
|
||||
const path = yield (0, svg_1.generateSvg)(totalPaths, scaleFactor || 1, defects);
|
||||
const generatSVGOptions = {
|
||||
paths: totalPaths,
|
||||
scaleFactor: scaleFactor !== null && scaleFactor !== void 0 ? scaleFactor : 1,
|
||||
defects: defects,
|
||||
};
|
||||
const { serverFilePath, totalHeight, totalWidth } = yield (0, svg_1.generateSvg)(generatSVGOptions);
|
||||
// Read the SVG files
|
||||
return res.json({ svgLink: path });
|
||||
return res.json({
|
||||
svgLink: serverFilePath,
|
||||
dim: { width: Math.ceil(totalWidth), height: Math.ceil(totalHeight) },
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err);
|
||||
@@ -108,4 +121,27 @@ router.post("/print", (req, res) => __awaiter(void 0, void 0, void 0, function*
|
||||
return res.status(500).json({ error: e });
|
||||
}
|
||||
}));
|
||||
router.get("/random-glyph/:username/:charName", (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
var _b, _c;
|
||||
let { username, charName } = req.params;
|
||||
if (!username || !charName) {
|
||||
return res.status(400).json({ error: "Missing username or char" });
|
||||
}
|
||||
try {
|
||||
// remove the double quotes form the charName
|
||||
charName = charName === "dot" ? "." : charName;
|
||||
const validCharName = (0, svg_1.validateName)(charName);
|
||||
const fullPath = yield (0, svg_1.getRandomEntityPath)(username, validCharName);
|
||||
const svgContent = yield (0, svg_1.fetchSVGContent)(fullPath);
|
||||
const { parent } = yield (0, svg_1.parseSVG)(svgContent);
|
||||
const width = (_b = parseFloat(parent.getAttribute("width"))) !== null && _b !== void 0 ? _b : 0;
|
||||
const height = (_c = parseFloat(parent.getAttribute("height"))) !== null && _c !== void 0 ? _c : 0;
|
||||
const warpedSvg = (0, svg_1.warpSvg)(svgContent, width, height);
|
||||
res.json(warpedSvg);
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err);
|
||||
res.status(500).json({ error: "Something went wrong!" });
|
||||
}
|
||||
}));
|
||||
exports.default = router;
|
||||
|
||||
Reference in New Issue
Block a user