Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
handle pup error
Browse files
src/routes/api/models/[id]/+server.ts
CHANGED
@@ -102,32 +102,35 @@ export async function GET({ url, params } : RequestEvent) {
|
|
102 |
'--disable-dev-shm-usage',
|
103 |
],
|
104 |
ignoreDefaultArgs: ['--disable-extensions']
|
105 |
-
})
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
|
|
|
|
|
|
|
|
129 |
|
130 |
-
await browser.close();
|
131 |
}
|
132 |
|
133 |
return json({
|
|
|
102 |
'--disable-dev-shm-usage',
|
103 |
],
|
104 |
ignoreDefaultArgs: ['--disable-extensions']
|
105 |
+
}).catch((err) => console.error(err))
|
106 |
+
|
107 |
+
if (browser) {
|
108 |
+
const page = await browser.newPage();
|
109 |
+
await page.goto(process.env.SPACE_HOST + '/metadata/models/' + model.id, {
|
110 |
+
waitUntil: 'networkidle0',
|
111 |
+
});
|
112 |
+
|
113 |
+
const buffer = await page.screenshot({
|
114 |
+
type: 'png',
|
115 |
+
});
|
116 |
+
|
117 |
+
const dir = await promises.opendir(process?.env?.PUBLIC_FILE_UPLOAD_DIR as string).catch(() => null)
|
118 |
+
if (!dir) await promises.mkdir(process?.env?.PUBLIC_FILE_UPLOAD_DIR as string)
|
119 |
+
const file_name_formatted = randomUUID() + "_" + "metadata" + model.id.replace("/", "-") + ".png"
|
120 |
+
await promises.writeFile(`${process.env.PUBLIC_FILE_UPLOAD_DIR}/${file_name_formatted}`, buffer)
|
121 |
+
|
122 |
+
await prisma.model.update({
|
123 |
+
where: {
|
124 |
+
id,
|
125 |
+
},
|
126 |
+
data: {
|
127 |
+
metadata: file_name_formatted
|
128 |
+
}
|
129 |
+
})
|
130 |
+
|
131 |
+
await browser.close();
|
132 |
+
}
|
133 |
|
|
|
134 |
}
|
135 |
|
136 |
return json({
|