Compare commits

...

2 Commits

Author SHA1 Message Date
Lamp fda3e02823 work around vrchat json parser bug 2024-01-31 04:35:53 +00:00
Lamp 41b122de60 Revert "ascii option"
This reverts commit 720640b054.
2024-01-31 03:49:16 +00:00
1 changed files with 19 additions and 6 deletions

25
app.js
View File

@ -26,15 +26,10 @@ router.get("/search", async ctx => {
var options = {
thumbnails: stringToBoolean(ctx.query.thumbnails),
icons: stringToBoolean(ctx.query.icons),
ascii: stringToBoolean(ctx.query.ascii)
icons: stringToBoolean(ctx.query.icons)
};
ctx.body = await cachedVRCYoutubeSearch(ctx.query.pool, query, options);
if (options.ascii) {
ctx.body = JSON.stringify(ctx.body).replace(/[\u007F-\uFFFF]/g, chr => "\\u" + ("0000" + chr.charCodeAt(0).toString(16)).slice(-4));
}
});
@ -80,5 +75,23 @@ router.get("/", ctx => {
// work around vrchat json parser bug https://feedback.vrchat.com/udon/p/braces-inside-strings-in-vrcjson-can-fail-to-deserialize
app.use(async (ctx, next) => {
await next();
if (ctx.type != "application/json") return;
ctx.body = structuredClone(ctx.body);
(function iterateObject(obj) {
for (var key in obj) {
if (typeof obj[key] == "string") {
obj[key] = obj[key].replace(/[\[\]{}]/g, chr => "\\u" + chr.charCodeAt(0).toString(16).padStart(4, '0'));
} else if (typeof obj[key] == "object") {
iterateObject(obj[key]);
}
}
})(ctx.body);
ctx.body = JSON.stringify(ctx.body).replaceAll("\\\\u", "\\u");
ctx.type = "json";
});
app.use(router.routes());
app.use(router.allowedMethods());