Spaces:
Running
Running
add puppeteer to check if it works
Browse files
src/routes/api/models/[id]/+server.ts
CHANGED
|
@@ -89,46 +89,46 @@ export async function GET({ url, params } : RequestEvent) {
|
|
| 89 |
}
|
| 90 |
|
| 91 |
// get puppeteer screenshot
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 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 |
-
|
| 131 |
-
|
| 132 |
|
| 133 |
return json({
|
| 134 |
model: {
|
|
|
|
| 89 |
}
|
| 90 |
|
| 91 |
// get puppeteer screenshot
|
| 92 |
+
if (!model.metadata && metadata) {
|
| 93 |
+
const browser = await puppeteer.launch({
|
| 94 |
+
headless: true,
|
| 95 |
+
defaultViewport: {
|
| 96 |
+
width: 1920,
|
| 97 |
+
height: 1080,
|
| 98 |
+
},
|
| 99 |
+
args: [
|
| 100 |
+
'--no-sandbox',
|
| 101 |
+
'--disable-setuid-sandbox',
|
| 102 |
+
'--disable-dev-shm-usage',
|
| 103 |
+
],
|
| 104 |
+
ignoreDefaultArgs: ['--disable-extensions']
|
| 105 |
+
});
|
| 106 |
+
|
| 107 |
+
const page = await browser.newPage();
|
| 108 |
+
await page.goto(process.env.SPACE_HOST + '/metadata/models/' + model.id, {
|
| 109 |
+
waitUntil: 'networkidle0',
|
| 110 |
+
});
|
| 111 |
+
|
| 112 |
+
const buffer = await page.screenshot({
|
| 113 |
+
type: 'png',
|
| 114 |
+
});
|
| 115 |
+
|
| 116 |
+
const dir = await promises.opendir(process?.env?.PUBLIC_FILE_UPLOAD_DIR as string).catch(() => null)
|
| 117 |
+
if (!dir) await promises.mkdir(process?.env?.PUBLIC_FILE_UPLOAD_DIR as string)
|
| 118 |
+
const file_name_formatted = randomUUID() + "_" + "metadata" + model.id.replace("/", "-") + ".png"
|
| 119 |
+
await promises.writeFile(`${process.env.PUBLIC_FILE_UPLOAD_DIR}/${file_name_formatted}`, buffer)
|
| 120 |
+
|
| 121 |
+
await prisma.model.update({
|
| 122 |
+
where: {
|
| 123 |
+
id,
|
| 124 |
+
},
|
| 125 |
+
data: {
|
| 126 |
+
metadata: file_name_formatted
|
| 127 |
+
}
|
| 128 |
+
})
|
| 129 |
+
|
| 130 |
+
await browser.close();
|
| 131 |
+
}
|
| 132 |
|
| 133 |
return json({
|
| 134 |
model: {
|