Spaces:
Running
Running
add path route model to update it manually
Browse files
src/routes/api/models/[id]/+server.ts
CHANGED
|
@@ -89,13 +89,23 @@ export async function GET({ url, params } : RequestEvent) {
|
|
| 89 |
})
|
| 90 |
}
|
| 91 |
|
| 92 |
-
export async function POST({ params,
|
| 93 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
| 99 |
}
|
| 100 |
|
| 101 |
const id = params.id?.replace("@", "/")
|
|
@@ -181,23 +191,13 @@ export async function DELETE({ params, cookies } : RequestEvent) {
|
|
| 181 |
})
|
| 182 |
}
|
| 183 |
|
| 184 |
-
export async function PATCH({ request, params
|
| 185 |
-
const
|
| 186 |
-
if (!token) {
|
| 187 |
-
return json({
|
| 188 |
-
error: {
|
| 189 |
-
token: "Token is required"
|
| 190 |
-
}
|
| 191 |
-
}, { status: 401 })
|
| 192 |
-
}
|
| 193 |
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
token: "Wrong castle fam :^)"
|
| 199 |
-
}
|
| 200 |
-
}, { status: 401 })
|
| 201 |
}
|
| 202 |
|
| 203 |
const id = params.id?.replace("@", "/")
|
|
|
|
| 89 |
})
|
| 90 |
}
|
| 91 |
|
| 92 |
+
export async function POST({ params, cookies, fetch } : RequestEvent) {
|
| 93 |
+
const token = cookies.get('hf_access_token')
|
| 94 |
+
if (!token) {
|
| 95 |
+
return json({
|
| 96 |
+
error: {
|
| 97 |
+
token: "Token is required"
|
| 98 |
+
}
|
| 99 |
+
}, { status: 401 })
|
| 100 |
+
}
|
| 101 |
|
| 102 |
+
const user = await tokenIsAvailable(token)
|
| 103 |
+
if (!user || !process.env.SECRET_HF_ADMIN?.includes(user.sub)) {
|
| 104 |
+
return json({
|
| 105 |
+
error: {
|
| 106 |
+
token: "Wrong castle fam :^)"
|
| 107 |
+
}
|
| 108 |
+
}, { status: 401 })
|
| 109 |
}
|
| 110 |
|
| 111 |
const id = params.id?.replace("@", "/")
|
|
|
|
| 191 |
})
|
| 192 |
}
|
| 193 |
|
| 194 |
+
export async function PATCH({ request, params } : RequestEvent) {
|
| 195 |
+
const headers = Object.fromEntries(request.headers.entries());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
|
| 197 |
+
if (headers["x-hf-token"] !== process.env.SECRET_HF_TOKEN) {
|
| 198 |
+
return Response.json({
|
| 199 |
+
message: "Wrong castle fam :^)"
|
| 200 |
+
}, { status: 401 });
|
|
|
|
|
|
|
|
|
|
| 201 |
}
|
| 202 |
|
| 203 |
const id = params.id?.replace("@", "/")
|