Skip to content

Commit 60f4d3a

Browse files
committed
feat: horde go brr
1 parent a842c1c commit 60f4d3a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+3269
-53
lines changed

.gitignore

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1 @@
1-
.DS_Store
2-
node_modules
3-
/build
4-
/.svelte-kit
5-
/package
6-
.env
7-
.env.*
8-
!.env.example
9-
vite.config.js.timestamp-*
10-
vite.config.ts.timestamp-*
1+
db

app/.env.example

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
PUBLIC_CARDBOARD_URL=
2+
CARDBOARD_TOKEN=
3+
CARDBOARD_SECRET=
4+
DATABASE_URL=postgresql://postgres:password@db:5432/postgres
5+
6+
PUBLIC_HORDE_CLIENT_NAME=guilded_diffusion
7+
PUBLIC_HORDE_CLIENT_VERSION=v0.0.1
8+
PUBLIC_HORDE_CLIENT_CONTACT=
File renamed without changes.
File renamed without changes.

app/.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
node_modules
3+
/build
4+
/.svelte-kit
5+
/package
6+
.env
7+
.env.*
8+
!.env.example
9+
vite.config.js.timestamp-*
10+
vite.config.ts.timestamp-*

.npmrc renamed to app/.npmrc

File renamed without changes.
File renamed without changes.
File renamed without changes.

app/.yarnrc.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
supportedArchitectures:
2+
os:
3+
- "current"
4+
- "darwin"
5+
- "linux"
6+
- "win32"
7+
cpu:
8+
- current"
9+
- "x64"
10+
- "ia32"

README.md renamed to app/README.md

File renamed without changes.

app/bun.lockb

133 KB
Binary file not shown.

app/package.json

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "diffusion",
3+
"version": "0.0.1",
4+
"private": true,
5+
"scripts": {
6+
"dev": "vite dev --host",
7+
"build": "vite build",
8+
"preview": "vite preview",
9+
"test": "npm run test:integration && npm run test:unit",
10+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
11+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
12+
"lint": "prettier --plugin-search-dir . --check . && eslint .",
13+
"format": "prettier --plugin-search-dir . --write .",
14+
"test:integration": "playwright test",
15+
"test:unit": "vitest"
16+
},
17+
"devDependencies": {
18+
"@playwright/test": "^1.28.1",
19+
"@skeletonlabs/skeleton": "^2.0.0",
20+
"@skeletonlabs/tw-plugin": "^0.1.0",
21+
"@sveltejs/adapter-auto": "^2.0.0",
22+
"@sveltejs/kit": "^1.20.4",
23+
"@types/node": "^20.6.0",
24+
"@typescript-eslint/eslint-plugin": "^5.45.0",
25+
"@typescript-eslint/parser": "^5.45.0",
26+
"autoprefixer": "^10.4.14",
27+
"cardboard.js": "^1.0.4",
28+
"eslint": "^8.28.0",
29+
"eslint-config-prettier": "^8.5.0",
30+
"eslint-plugin-svelte": "^2.30.0",
31+
"postcss": "^8.4.24",
32+
"postcss-load-config": "^4.0.1",
33+
"prettier": "^2.8.0",
34+
"prettier-plugin-svelte": "^2.10.1",
35+
"svelte": "^4.0.5",
36+
"svelte-check": "^3.4.3",
37+
"tailwindcss": "^3.3.2",
38+
"tslib": "^2.4.1",
39+
"typescript": "^5.0.0",
40+
"vite": "^4.4.2",
41+
"vitest": "^0.32.2"
42+
},
43+
"type": "module",
44+
"dependencies": {
45+
"@prisma/client": "5.2.0",
46+
"@thunder04/supermap": "^3.0.2",
47+
"iconify-icon": "^1.0.8",
48+
"prisma": "^5.2.0"
49+
}
50+
}
File renamed without changes.

app/postcss.config.cjs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const tailwindcss = require('tailwindcss');
2+
const autoprefixer = require('autoprefixer');
3+
4+
const config = {
5+
plugins: [
6+
//Some plugins, like tailwindcss/nesting, need to run before Tailwind,
7+
tailwindcss(),
8+
//But others, like autoprefixer, need to run after,
9+
autoprefixer
10+
]
11+
};
12+
13+
module.exports = config;

app/prisma/schema.prisma

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
generator client {
2+
provider = "prisma-client-js"
3+
binaryTargets = ["native"]
4+
}
5+
6+
datasource db {
7+
provider = "postgresql"
8+
url = env("DATABASE_URL")
9+
}
10+
11+
model DiffusionUser {
12+
id String @id @unique
13+
username String
14+
avatar String @default("/poop.png")
15+
banner String @default("https://img.guildedcdn.com/asset/Default/ProfileBannerLarge.png")
16+
hordeKey String @default("0000000000")
17+
createdAt DateTime @default(now())
18+
editedAt DateTime @default(now())
19+
}
20+
21+
// model GeneratedImage {
22+
23+
// }

src/app.d.ts renamed to app/src/app.d.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
// See https://kit.svelte.dev/docs/types#app
2+
3+
import type { GuildedUser } from 'cardboard.js';
4+
5+
export interface DiffusionUser extends GuildedUser {
6+
hordeKey?: string;
7+
}
8+
29
// for information about these interfaces
310
declare global {
411
namespace App {
512
// interface Error {}
6-
// interface Locals {}
13+
interface Locals {
14+
user: DiffusionUser;
15+
}
716
// interface PageData {}
817
// interface Platform {}
918
}
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<!DOCTYPE html>
2-
<html lang="en">
2+
<html lang="en" class="dark">
33
<head>
44
<meta charset="utf-8" />
55
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
66
<meta name="viewport" content="width=device-width" />
77
%sveltekit.head%
88
</head>
9-
<body data-sveltekit-preload-data="hover">
10-
<div style="display: contents">%sveltekit.body%</div>
9+
<body data-sveltekit-preload-data="hover" data-theme="wintry">
10+
<div style="display: contents" class="h-full overflow-hidden">%sveltekit.body%</div>
1111
</body>
1212
</html>

app/src/app.postcss

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* Write your global styles here, in PostCSS syntax */
2+
@tailwind base;
3+
@tailwind components;
4+
@tailwind utilities;
5+
6+
@layer components {
7+
h1 {
8+
@apply h1;
9+
}
10+
h2 {
11+
@apply h2;
12+
}
13+
h3 {
14+
@apply h3;
15+
}
16+
h4 {
17+
@apply h4;
18+
}
19+
h5 {
20+
@apply h5;
21+
}
22+
h6 {
23+
@apply h6;
24+
}
25+
input {
26+
@apply input;
27+
}
28+
}

app/src/hooks.server.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { cb, db } from '$lib/server';
2+
3+
import type { Handle } from '@sveltejs/kit';
4+
import type { DiffusionUser } from './app';
5+
6+
export const handle: Handle = async ({ event, resolve }) => {
7+
const session = event.cookies.get('session');
8+
if (!session || session == '') {
9+
return await resolve(event);
10+
}
11+
const user = await cb.getUserInfo(session) as DiffusionUser;
12+
if (!user || !user.id || user.id == '') {
13+
event.cookies.set('session', '', {
14+
path: '/',
15+
expires: new Date(0)
16+
});
17+
return resolve(event);
18+
}
19+
let localUser = await db.diffusionUser.findUnique({
20+
where: {
21+
id: user.id
22+
}
23+
})
24+
if (!localUser) {
25+
localUser = await db.diffusionUser.create({
26+
data: {
27+
id: user.id,
28+
username: user.name,
29+
avatar: user.avatar,
30+
banner: user.banner,
31+
}
32+
})
33+
}
34+
user.hordeKey = localUser.hordeKey;
35+
event.locals.user = user;
36+
return await resolve(event);
37+
};
File renamed without changes.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './'

app/src/lib/client/fragments/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script lang="ts">
2+
import 'iconify-icon'
3+
import {PUBLIC_CARDBOARD_URL} from '$env/static/public'
4+
</script>
5+
6+
<a href={PUBLIC_CARDBOARD_URL}>
7+
<button class="btn variant-ghost-surface flex gap-2">
8+
<iconify-icon icon="fa-brands:guilded" />
9+
Login with Guilded
10+
</button>
11+
</a>

app/src/lib/client/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './components'
2+
export * from './fragments'

app/src/lib/common/ai-horde/index.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { Model, UserDetails } from './types'
2+
3+
export class HordeClient {
4+
private _baseURL: string
5+
private _clientAgent: string
6+
protected client_name: string
7+
protected client_version: string
8+
protected client_contact: string
9+
constructor(client_name: string, client_version: string, client_contact: string) {
10+
this.client_name = client_name
11+
this.client_version = client_version
12+
this.client_contact = client_contact
13+
this._clientAgent = `${this.client_name}:${this.client_version}:${this.client_contact}`
14+
this._baseURL = 'https://stablehorde.net/api/v2'
15+
}
16+
public async findUser (token: string) {
17+
return (await fetch (`${this._baseURL}/find_user`, {headers: {
18+
apikey: token,
19+
'Client-Agent': this._clientAgent
20+
}})).json() as unknown as UserDetails
21+
}
22+
public async getModels (type: "image" | "text") {
23+
return (await fetch (`${this._baseURL}/status/models?type=${type}`, {headers: {
24+
'Client-Agent': this._clientAgent
25+
}})).json() as unknown as Model[]
26+
}
27+
}
28+
29+
export * from './types'

0 commit comments

Comments
 (0)