radames commited on
Commit
6946674
โ€ข
1 Parent(s): c413f97

liveblocks auth api

Browse files
frontend/.env.development.example CHANGED
@@ -1,3 +1,3 @@
1
  PUBLIC_WS_INPAINTING="ws://0.0.0.0:7860/gradio/queue/join"
2
  PUBLIC_UPLOADS="https://d26smi9133w0oo.cloudfront.net/uploads"
3
- PUBLIC_UPLOAD_URL="/server/uploadfile/"
 
1
  PUBLIC_WS_INPAINTING="ws://0.0.0.0:7860/gradio/queue/join"
2
  PUBLIC_UPLOADS="https://d26smi9133w0oo.cloudfront.net/uploads"
3
+ PUBLIC_API_BASE="/server/api"
frontend/.env.example CHANGED
@@ -1,3 +1,3 @@
1
  PUBLIC_WS_INPAINTING="wss://spaces.huggingface.tech/huggingface-projects/stable-diffusion-multiplayer/gradio/queue/join"
2
  PUBLIC_UPLOADS="https://d26smi9133w0oo.cloudfront.net/uploads"
3
- PUBLIC_UPLOAD_URL="/embed/huggingface-projects/stable-diffusion-multiplayer/uploadfile/"
 
1
  PUBLIC_WS_INPAINTING="wss://spaces.huggingface.tech/huggingface-projects/stable-diffusion-multiplayer/gradio/queue/join"
2
  PUBLIC_UPLOADS="https://d26smi9133w0oo.cloudfront.net/uploads"
3
+ PUBLIC_API_BASE="/embed/huggingface-projects/stable-diffusion-multiplayer/api"
frontend/src/lib/constants.ts CHANGED
@@ -5,24 +5,5 @@ export const COLORS = Object.values(colors)
5
  .map((e) => e['200'])
6
  .slice(0, 18);
7
 
8
- // all animal emojis list
9
- export const EMOJIS = [
10
- '๐Ÿถ',
11
- '๐Ÿฑ',
12
- '๐Ÿญ',
13
- '๐Ÿน',
14
- '๐Ÿฐ',
15
- '๐ŸฆŠ',
16
- '๐Ÿป',
17
- '๐Ÿผ',
18
- '๐Ÿจ',
19
- '๐Ÿฏ',
20
- '๐Ÿฆ',
21
- '๐Ÿฎ',
22
- '๐Ÿฒ',
23
- '๐ŸŒš',
24
- '๐ŸŒ',
25
- '๐ŸŒž',
26
- '๐ŸŒ›',
27
- '๐ŸŒœ'
28
- ];
 
5
  .map((e) => e['200'])
6
  .slice(0, 18);
7
 
8
+ export const EMOJIS = ['๐Ÿ', '๐ŸŒ', '๐Ÿž', '๐Ÿœ', '๐Ÿฆ‹', '๐Ÿ›', '๐Ÿ', '๐Ÿž', '๐ŸฆŸ', '๐Ÿฆ—', '๐Ÿ•ท', '๐Ÿฆ‚', '๐Ÿข', '๐Ÿ', '๐ŸฆŽ', '๐Ÿฆ–', '๐Ÿฆ•', '๐Ÿ™', '๐Ÿฆ‘', '๐Ÿ ', '๐ŸŸ', '๐Ÿก', '๐Ÿฌ', '๐Ÿฆˆ', '๐Ÿณ', '๐Ÿ‹', '๐ŸŠ', '๐Ÿ…', '๐Ÿ†', '๐Ÿฆ“', '๐Ÿฆ', '๐Ÿฆง', '๐Ÿ˜', '๐Ÿฆ›', '๐Ÿฆ', '๐Ÿช', '๐Ÿซ', '๐Ÿฆ’', '๐Ÿƒ', '๐Ÿ‚', '๐Ÿ„', '๐ŸŽ', '๐Ÿ–',
9
+ '๐Ÿ', '๐Ÿ‘', '๐Ÿ', '๐Ÿ•', '๐Ÿฉ', '๐Ÿˆ', '๐Ÿ“', '๐Ÿฆƒ', '๐Ÿฆ…', '๐Ÿฆ†', '๐Ÿฆข', '๐Ÿฆ‰', '๐Ÿฆš', '๐Ÿฆœ', '๐Ÿฆ‡', '๐Ÿ', '๐Ÿ€', '๐Ÿฟ', '๐Ÿ‡', '๐Ÿฟ', '๐Ÿฆ”', '๐Ÿฆ‡', '๐Ÿป', '๐Ÿป', '๐Ÿจ', '๐Ÿผ', '๐Ÿต', '๐Ÿ™ˆ', '๐Ÿ™‰', '๐Ÿ™Š', '๐Ÿ’', '๐Ÿ‰', '๐Ÿฒ', '๐Ÿฆ•', '๐Ÿฆ–', '๐ŸŠ', '๐Ÿข', '๐ŸฆŽ', '๐Ÿ', '๐Ÿฆ', '๐Ÿง', '๐Ÿฆ…', '๐Ÿฆ†', '๐Ÿฆ‰', '๐Ÿฆ‡']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
frontend/src/lib/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { PUBLIC_UPLOAD_URL } from '$env/static/public';
2
 
3
  export function base64ToBlob(base64image: string): Promise<Blob> {
4
  return new Promise((resolve) => {
@@ -32,7 +32,7 @@ export async function uploadImage(imagBlob: Blob, prompt: string, key: string):
32
  const formData = new FormData()
33
  formData.append('file', file)
34
 
35
- const response = await fetch(PUBLIC_UPLOAD_URL, {
36
  method: 'POST',
37
  body: formData
38
  });
 
1
+ import { PUBLIC_API_BASE } from '$env/static/public';
2
 
3
  export function base64ToBlob(base64image: string): Promise<Blob> {
4
  return new Promise((resolve) => {
 
32
  const formData = new FormData()
33
  formData.append('file', file)
34
 
35
+ const response = await fetch(PUBLIC_API_BASE + "/uploadfile", {
36
  method: 'POST',
37
  body: formData
38
  });
frontend/src/routes/+layout.ts CHANGED
@@ -1 +1,6 @@
1
- export const prerender = true;
 
 
 
 
 
 
1
+ import { PUBLIC_API_BASE } from '$env/static/public';
2
+
3
+ export async function load({ fetch }) {
4
+ const rooms = await fetch(PUBLIC_API_BASE + "/rooms").then((res) => res.json());
5
+ return { rooms };
6
+ }
frontend/src/routes/+page.svelte CHANGED
@@ -15,11 +15,18 @@
15
  import LiveblocksProvider from '$lib/liveblocks/LiveblocksProvider.svelte';
16
  import RoomProvider from '$lib/liveblocks/RoomProvider.svelte';
17
  import App from '$lib/App.svelte';
 
 
 
 
18
 
19
  let roomId: string;
20
  let loaded = false;
21
  let client: Client;
22
 
 
 
 
23
  onMount(() => {
24
  document.addEventListener('wheel', (e) => e.preventDefault(), { passive: false });
25
 
@@ -29,7 +36,8 @@
29
 
30
  // Connect to the authentication API for Liveblocks
31
  client = createClient({
32
- publicApiKey: 'pk_test_JlUZGH3kQmhmZQiqU2l8eIi5'
 
33
  });
34
 
35
  loaded = true;
 
15
  import LiveblocksProvider from '$lib/liveblocks/LiveblocksProvider.svelte';
16
  import RoomProvider from '$lib/liveblocks/RoomProvider.svelte';
17
  import App from '$lib/App.svelte';
18
+ import type { PageData } from './$types';
19
+ import { PUBLIC_API_BASE } from '$env/static/public';
20
+
21
+ export let data: PageData;
22
 
23
  let roomId: string;
24
  let loaded = false;
25
  let client: Client;
26
 
27
+ $: {
28
+ console.log('data changed', data);
29
+ }
30
  onMount(() => {
31
  document.addEventListener('wheel', (e) => e.preventDefault(), { passive: false });
32
 
 
36
 
37
  // Connect to the authentication API for Liveblocks
38
  client = createClient({
39
+ // publicApiKey: 'pk_test_JlUZGH3kQmhmZQiqU2l8eIi5'
40
+ authEndpoint: PUBLIC_API_BASE + '/auth'
41
  });
42
 
43
  loaded = true;
stablediffusion-infinity/app.py CHANGED
@@ -3,7 +3,7 @@ import os
3
 
4
  from pathlib import Path
5
  import uvicorn
6
- from fastapi import FastAPI, BackgroundTasks, HTTPException, UploadFile, Depends, status
7
  from fastapi.staticfiles import StaticFiles
8
  from fastapi.middleware.cors import CORSMiddleware
9
  from fastapi_utils.tasks import repeat_every
@@ -21,6 +21,7 @@ import boto3
21
  import magic
22
  import sqlite3
23
  import requests
 
24
 
25
  AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
26
  AWS_SECRET_KEY = os.getenv('AWS_SECRET_KEY')
@@ -36,6 +37,7 @@ FILE_TYPES = {
36
  'image/jpeg': 'jpg',
37
  }
38
  DB_PATH = Path("rooms.db")
 
39
  app = FastAPI()
40
 
41
  print("DB_PATH", DB_PATH)
@@ -55,7 +57,6 @@ def get_db():
55
  db.close()
56
 
57
 
58
-
59
  s3 = boto3.client(service_name='s3',
60
  aws_access_key_id=AWS_ACCESS_KEY_ID,
61
  aws_secret_access_key=AWS_SECRET_KEY)
@@ -115,6 +116,7 @@ def get_model():
115
  # model["img2img"]
116
 
117
 
 
118
  # get_model()
119
 
120
 
@@ -280,13 +282,32 @@ async def sync_rooms():
280
  print(e)
281
  print("Rooms update failed")
282
 
283
- @app.get('/rooms')
 
284
  async def get_rooms(db: sqlite3.Connection = Depends(get_db)):
285
  rooms = db.execute("SELECT * FROM rooms").fetchall()
286
  return rooms
287
 
288
 
289
- @app.post('/uploadfile/')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290
  async def create_upload_file(background_tasks: BackgroundTasks, file: UploadFile):
291
  contents = await file.read()
292
  file_size = len(contents)
 
3
 
4
  from pathlib import Path
5
  import uvicorn
6
+ from fastapi import FastAPI, BackgroundTasks, HTTPException, UploadFile, Depends, status, Request
7
  from fastapi.staticfiles import StaticFiles
8
  from fastapi.middleware.cors import CORSMiddleware
9
  from fastapi_utils.tasks import repeat_every
 
21
  import magic
22
  import sqlite3
23
  import requests
24
+ import uuid
25
 
26
  AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
27
  AWS_SECRET_KEY = os.getenv('AWS_SECRET_KEY')
 
37
  'image/jpeg': 'jpg',
38
  }
39
  DB_PATH = Path("rooms.db")
40
+
41
  app = FastAPI()
42
 
43
  print("DB_PATH", DB_PATH)
 
57
  db.close()
58
 
59
 
 
60
  s3 = boto3.client(service_name='s3',
61
  aws_access_key_id=AWS_ACCESS_KEY_ID,
62
  aws_secret_access_key=AWS_SECRET_KEY)
 
116
  # model["img2img"]
117
 
118
 
119
+ # init model on startup
120
  # get_model()
121
 
122
 
 
282
  print(e)
283
  print("Rooms update failed")
284
 
285
+
286
+ @app.get('/api/rooms')
287
  async def get_rooms(db: sqlite3.Connection = Depends(get_db)):
288
  rooms = db.execute("SELECT * FROM rooms").fetchall()
289
  return rooms
290
 
291
 
292
+ @app.post('/api/auth')
293
+ async def autorize(request: Request):
294
+ data = await request.json()
295
+ room = data["room"]
296
+ payload = {
297
+ "userId": str(uuid.uuid4()),
298
+ "userInfo": {
299
+ "name": "Anon"
300
+ }}
301
+
302
+ response = requests.post(f"https://api.liveblocks.io/v2/rooms/{room}/authorize",
303
+ headers={"Authorization": f"Bearer {LIVEBLOCKS_SECRET}"}, json=payload)
304
+ if response.status_code == 200:
305
+ return response.json()
306
+ else:
307
+ raise Exception(response.status_code, response.text)
308
+
309
+
310
+ @ app.post('/api/uploadfile/')
311
  async def create_upload_file(background_tasks: BackgroundTasks, file: UploadFile):
312
  contents = await file.read()
313
  file_size = len(contents)