enzostvs HF staff commited on
Commit
b628664
β€’
1 Parent(s): 8fce765

run svelte with express

Browse files
entrypoint.sh CHANGED
@@ -4,4 +4,4 @@ npm run build &&
4
  npx prisma generate &&
5
  npx prisma migrate deploy &&
6
  npx prisma db push &&
7
- node build
 
4
  npx prisma generate &&
5
  npx prisma migrate deploy &&
6
  npx prisma db push &&
7
+ node server.js
package-lock.json CHANGED
@@ -16,6 +16,7 @@
16
  "@sveltejs/adapter-node": "^1.3.1",
17
  "aws-sdk": "^2.1538.0",
18
  "cookie": "^0.6.0",
 
19
  "desm": "^1.3.1",
20
  "express": "^4.18.2",
21
  "js-cookie": "^3.0.5",
@@ -3750,6 +3751,18 @@
3750
  "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
3751
  "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ=="
3752
  },
 
 
 
 
 
 
 
 
 
 
 
 
3753
  "node_modules/cross-spawn": {
3754
  "version": "7.0.3",
3755
  "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
@@ -5350,7 +5363,6 @@
5350
  "version": "4.1.1",
5351
  "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
5352
  "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
5353
- "dev": true,
5354
  "engines": {
5355
  "node": ">=0.10.0"
5356
  }
 
16
  "@sveltejs/adapter-node": "^1.3.1",
17
  "aws-sdk": "^2.1538.0",
18
  "cookie": "^0.6.0",
19
+ "cors": "^2.8.5",
20
  "desm": "^1.3.1",
21
  "express": "^4.18.2",
22
  "js-cookie": "^3.0.5",
 
3751
  "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
3752
  "integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ=="
3753
  },
3754
+ "node_modules/cors": {
3755
+ "version": "2.8.5",
3756
+ "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
3757
+ "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
3758
+ "dependencies": {
3759
+ "object-assign": "^4",
3760
+ "vary": "^1"
3761
+ },
3762
+ "engines": {
3763
+ "node": ">= 0.10"
3764
+ }
3765
+ },
3766
  "node_modules/cross-spawn": {
3767
  "version": "7.0.3",
3768
  "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
 
5363
  "version": "4.1.1",
5364
  "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
5365
  "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==",
 
5366
  "engines": {
5367
  "node": ">=0.10.0"
5368
  }
package.json CHANGED
@@ -49,6 +49,7 @@
49
  "@sveltejs/adapter-node": "^1.3.1",
50
  "aws-sdk": "^2.1538.0",
51
  "cookie": "^0.6.0",
 
52
  "desm": "^1.3.1",
53
  "express": "^4.18.2",
54
  "js-cookie": "^3.0.5",
 
49
  "@sveltejs/adapter-node": "^1.3.1",
50
  "aws-sdk": "^2.1538.0",
51
  "cookie": "^0.6.0",
52
+ "cors": "^2.8.5",
53
  "desm": "^1.3.1",
54
  "express": "^4.18.2",
55
  "js-cookie": "^3.0.5",
server.js ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { handler } from './build/handler.js';
2
+ import express from 'express';
3
+
4
+ const app = express();
5
+
6
+ // Serve your "data/assets" folder
7
+ app.use(express.static('data/assets'))
8
+
9
+ // let SvelteKit handle everything else, including serving prerendered pages and static assets
10
+ app.use(handler);
11
+
12
+ app.listen(3000, () => {
13
+ console.log('listening on port 3000');
14
+ });
src/routes/api/@me/+server.ts CHANGED
@@ -1,6 +1,5 @@
1
  import { json, type RequestEvent } from '@sveltejs/kit';
2
  import prisma from '$lib/prisma';
3
- import { env } from '$env/dynamic/private';
4
 
5
  /** @type {import('./$types').RequestHandler} */
6
 
@@ -63,7 +62,7 @@ export async function GET(request : RequestEvent) {
63
  return json({
64
  user: {
65
  ...user,
66
- is_admin: env.SECRET_HF_ADMIN.includes(user.sub)
67
  }
68
  })
69
  }
 
1
  import { json, type RequestEvent } from '@sveltejs/kit';
2
  import prisma from '$lib/prisma';
 
3
 
4
  /** @type {import('./$types').RequestHandler} */
5
 
 
62
  return json({
63
  user: {
64
  ...user,
65
+ is_admin: process?.env?.SECRET_HF_ADMIN?.includes(user.sub)
66
  }
67
  })
68
  }
src/routes/api/community/[id]/+server.ts CHANGED
@@ -1,6 +1,5 @@
1
  import { json, type RequestEvent } from '@sveltejs/kit';
2
  import { promises } from 'fs';
3
- import { env } from '$env/dynamic/public';
4
 
5
  import prisma from '$lib/prisma';
6
  import { tokenIsAvailable } from '$lib/utils';
@@ -32,7 +31,6 @@ export async function GET({ params, url } : RequestEvent) {
32
  },
33
  model: {
34
  select: {
35
- title: true,
36
  image: true,
37
  id: true,
38
  }
@@ -157,7 +155,7 @@ export async function DELETE({ params, cookies }: RequestEvent) {
157
  }
158
  })
159
 
160
- await promises.unlink(`${env.PUBLIC_FILE_UPLOAD_DIR}/${gallery?.image}`)
161
 
162
  return json({
163
  success: true
 
1
  import { json, type RequestEvent } from '@sveltejs/kit';
2
  import { promises } from 'fs';
 
3
 
4
  import prisma from '$lib/prisma';
5
  import { tokenIsAvailable } from '$lib/utils';
 
31
  },
32
  model: {
33
  select: {
 
34
  image: true,
35
  id: true,
36
  }
 
155
  }
156
  })
157
 
158
+ await promises.unlink(`${process.env.PUBLIC_FILE_UPLOAD_DIR}/${gallery?.image}`)
159
 
160
  return json({
161
  success: true
src/routes/api/generate/+server.ts CHANGED
@@ -1,8 +1,6 @@
1
  /** @type {import('./$types').RequestHandler} */
2
 
3
  import { json, type RequestEvent } from '@sveltejs/kit';
4
- import { env } from '$env/dynamic/private'
5
- import { env as publicEnv } from '$env/dynamic/public';
6
  import { promises } from 'fs';
7
  import { randomUUID } from 'crypto';
8
 
@@ -38,10 +36,10 @@ export async function POST({ request, cookies } : RequestEvent) {
38
  }
39
  })
40
 
41
- const response = await fetch(env.SECRET_INFERENCE_API_URL + "/models/" + generation?.model?.id, {
42
  method: "POST",
43
  headers: {
44
- Authorization: `Bearer ${env.SECRET_HF_TOKEN}`,
45
  'Content-Type': 'application/json',
46
  ['x-use-cache']: "0"
47
  },
@@ -75,10 +73,10 @@ export async function POST({ request, cookies } : RequestEvent) {
75
  if (token) {
76
  const user = await tokenIsAvailable(token)
77
  if (user?.sub) {
78
- const dir = await promises.opendir(publicEnv.PUBLIC_FILE_UPLOAD_DIR).catch(() => null)
79
- if (!dir) await promises.mkdir(publicEnv.PUBLIC_FILE_UPLOAD_DIR)
80
  const file_name_formatted = randomUUID() + "_" + generation?.inputs?.replaceAll(/[^a-zA-Z0-9]/g, "-") + ".png"
81
- await promises.writeFile(`${publicEnv.PUBLIC_FILE_UPLOAD_DIR}/${file_name_formatted}`, response)
82
 
83
  gallery = await prisma.gallery.create({
84
  data: {
 
1
  /** @type {import('./$types').RequestHandler} */
2
 
3
  import { json, type RequestEvent } from '@sveltejs/kit';
 
 
4
  import { promises } from 'fs';
5
  import { randomUUID } from 'crypto';
6
 
 
36
  }
37
  })
38
 
39
+ const response = await fetch(process.env.SECRET_INFERENCE_API_URL + "/models/" + generation?.model?.id, {
40
  method: "POST",
41
  headers: {
42
+ Authorization: `Bearer ${process.env.SECRET_HF_TOKEN}`,
43
  'Content-Type': 'application/json',
44
  ['x-use-cache']: "0"
45
  },
 
73
  if (token) {
74
  const user = await tokenIsAvailable(token)
75
  if (user?.sub) {
76
+ const dir = await promises.opendir(process.env.PUBLIC_FILE_UPLOAD_DIR).catch(() => null)
77
+ if (!dir) await promises.mkdir(process.env.PUBLIC_FILE_UPLOAD_DIR)
78
  const file_name_formatted = randomUUID() + "_" + generation?.inputs?.replaceAll(/[^a-zA-Z0-9]/g, "-") + ".png"
79
+ await promises.writeFile(`${process.env.PUBLIC_FILE_UPLOAD_DIR}/${file_name_formatted}`, response)
80
 
81
  gallery = await prisma.gallery.create({
82
  data: {
src/routes/api/images/[id]/+server.ts CHANGED
@@ -1,6 +1,5 @@
1
  import { json, type RequestEvent } from '@sveltejs/kit';
2
  import { promises } from 'fs';
3
- import { env } from '$env/dynamic/public';
4
 
5
  import prisma from '$lib/prisma';
6
 
@@ -25,7 +24,7 @@ export async function GET({ params } : RequestEvent) {
25
  }, { status: 404 })
26
  }
27
 
28
- const file = await promises.readFile(`${env.PUBLIC_FILE_UPLOAD_DIR}/${gallery.image}`)
29
  return new Response(file, {
30
  headers: {
31
  'Content-Type': 'image/png',
 
1
  import { json, type RequestEvent } from '@sveltejs/kit';
2
  import { promises } from 'fs';
 
3
 
4
  import prisma from '$lib/prisma';
5
 
 
24
  }, { status: 404 })
25
  }
26
 
27
+ const file = await promises.readFile(`${process.env.PUBLIC_FILE_UPLOAD_DIR}/${gallery.image}`)
28
  return new Response(file, {
29
  headers: {
30
  'Content-Type': 'image/png',
src/routes/api/models/+server.ts CHANGED
@@ -1,6 +1,5 @@
1
  import { json, type RequestEvent } from '@sveltejs/kit';
2
  import prisma from '$lib/prisma';
3
- import { env } from '$env/dynamic/private';
4
 
5
  import { tokenIsAvailable } from '$lib/utils';
6
 
@@ -13,7 +12,7 @@ export async function GET(request : RequestEvent) {
13
  if (token) {
14
  const user = await tokenIsAvailable(token)
15
  if (user) {
16
- IS_ADMIN = env.SECRET_HF_ADMIN.includes(user.sub)
17
  }
18
  }
19
 
 
1
  import { json, type RequestEvent } from '@sveltejs/kit';
2
  import prisma from '$lib/prisma';
 
3
 
4
  import { tokenIsAvailable } from '$lib/utils';
5
 
 
12
  if (token) {
13
  const user = await tokenIsAvailable(token)
14
  if (user) {
15
+ IS_ADMIN = process.env.SECRET_HF_ADMIN.includes(user.sub)
16
  }
17
  }
18
 
src/routes/api/models/[id]/+server.ts CHANGED
@@ -1,5 +1,4 @@
1
  import { json, type RequestEvent } from '@sveltejs/kit';
2
- import { env } from '$env/dynamic/private'
3
  import prisma from '$lib/prisma';
4
  import { tokenIsAvailable } from '$lib/utils';
5
 
@@ -71,7 +70,7 @@ export async function GET({ url, params } : RequestEvent) {
71
  if (full) {
72
  const hf_model_request = await fetch(`https://huggingface.co/api/models/${id}`, {
73
  headers: {
74
- "Authorization": `Bearer ${env.SECRET_HF_TOKEN}`
75
  }
76
  })
77
  const hf_model_response = await hf_model_request.json();
@@ -101,7 +100,7 @@ export async function POST({ params, cookies } : RequestEvent) {
101
  }
102
 
103
  const user = await tokenIsAvailable(token)
104
- if (!user || !env.SECRET_HF_ADMIN.includes(user.sub)) {
105
  return json({
106
  error: {
107
  token: "Wrong castle fam :^)"
@@ -150,7 +149,7 @@ export async function DELETE({ params, cookies } : RequestEvent) {
150
  }
151
 
152
  const user = await tokenIsAvailable(token)
153
- if (!user || !env.SECRET_HF_ADMIN.includes(user.sub)) {
154
  return json({
155
  error: {
156
  token: "Wrong castle fam :^)"
 
1
  import { json, type RequestEvent } from '@sveltejs/kit';
 
2
  import prisma from '$lib/prisma';
3
  import { tokenIsAvailable } from '$lib/utils';
4
 
 
70
  if (full) {
71
  const hf_model_request = await fetch(`https://huggingface.co/api/models/${id}`, {
72
  headers: {
73
+ "Authorization": `Bearer ${process.env.SECRET_HF_TOKEN}`
74
  }
75
  })
76
  const hf_model_response = await hf_model_request.json();
 
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 :^)"
 
149
  }
150
 
151
  const user = await tokenIsAvailable(token)
152
+ if (!user || !process.env.SECRET_HF_ADMIN.includes(user.sub)) {
153
  return json({
154
  error: {
155
  token: "Wrong castle fam :^)"
src/routes/api/scrap-models/+server.ts CHANGED
@@ -3,12 +3,11 @@
3
  import { json } from '@sveltejs/kit';
4
  // import moment from 'moment';
5
  import prisma from '$lib/prisma';
6
- import { env } from '$env/dynamic/private'
7
 
8
  export async function POST({ request }) {
9
  const headers = Object.fromEntries(request.headers.entries());
10
 
11
- if (headers["x-hf-token"] !== env.SECRET_HF_TOKEN) {
12
  return Response.json({
13
  message: "Wrong castle fam :^)"
14
  }, { status: 401 });
 
3
  import { json } from '@sveltejs/kit';
4
  // import moment from 'moment';
5
  import prisma from '$lib/prisma';
 
6
 
7
  export async function POST({ request }) {
8
  const headers = Object.fromEntries(request.headers.entries());
9
 
10
+ if (headers["x-hf-token"] !== process.env.SECRET_HF_TOKEN) {
11
  return Response.json({
12
  message: "Wrong castle fam :^)"
13
  }, { status: 401 });