enzostvs HF staff commited on
Commit
e32b26d
β€’
1 Parent(s): 74cddec

handle pup error

Browse files
Files changed (1) hide show
  1. src/routes/api/models/[id]/+server.ts +28 -25
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
- 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({
 
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({