Spaces:
Runtime error
Runtime error
add path route model to update it manually
Browse files
src/routes/api/models/[id]/+server.ts
CHANGED
|
@@ -189,4 +189,55 @@ export async function DELETE({ params, cookies } : RequestEvent) {
|
|
| 189 |
return json({
|
| 190 |
success: true
|
| 191 |
})
|
| 192 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
return json({
|
| 190 |
success: true
|
| 191 |
})
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
export async function PATCH({ request, params, cookies } : RequestEvent) {
|
| 195 |
+
const token = cookies.get('hf_access_token')
|
| 196 |
+
if (!token) {
|
| 197 |
+
return json({
|
| 198 |
+
error: {
|
| 199 |
+
token: "Token is required"
|
| 200 |
+
}
|
| 201 |
+
}, { status: 401 })
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
const user = await tokenIsAvailable(token)
|
| 205 |
+
if (!user || !process.env.SECRET_HF_ADMIN?.includes(user.sub)) {
|
| 206 |
+
return json({
|
| 207 |
+
error: {
|
| 208 |
+
token: "Wrong castle fam :^)"
|
| 209 |
+
}
|
| 210 |
+
}, { status: 401 })
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
const id = params.id?.replace("@", "/")
|
| 214 |
+
|
| 215 |
+
const model = await prisma.model.findFirst({
|
| 216 |
+
where: {
|
| 217 |
+
id,
|
| 218 |
+
}
|
| 219 |
+
})
|
| 220 |
+
|
| 221 |
+
if (!model) {
|
| 222 |
+
return json({
|
| 223 |
+
error: {
|
| 224 |
+
token: "Model not found"
|
| 225 |
+
}
|
| 226 |
+
}, { status: 404 })
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
const body = await request.json()
|
| 230 |
+
|
| 231 |
+
await prisma.model.update({
|
| 232 |
+
where: {
|
| 233 |
+
id,
|
| 234 |
+
},
|
| 235 |
+
data: {
|
| 236 |
+
...body
|
| 237 |
+
}
|
| 238 |
+
})
|
| 239 |
+
|
| 240 |
+
return json({
|
| 241 |
+
success: true
|
| 242 |
+
})
|
| 243 |
+
}
|