An atproto based writing game loosely inspired by Fiasco!
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

wip: sent to desktop

+83 -112
-6
src/api/db.ts
··· 1 - import { drizzle, BetterSQLite3Database } from 'drizzle-orm/better-sqlite3'; 2 - import Database from "better-sqlite3"; 3 - 4 - const sqlite = new Database('./drizzle/db.sqlite'); 5 - 6 - export const db: BetterSQLite3Database = drizzle(sqlite);
+67 -67
src/api/server.ts
··· 1 - "use server"; 2 - import { redirect } from "@solidjs/router"; 3 - import { useSession } from "vinxi/http"; 4 - import { eq } from "drizzle-orm"; 5 - import { db } from "./db"; 6 - import { Users } from "../../drizzle/schema"; 1 + // "use server"; 2 + // import { redirect } from "@solidjs/router"; 3 + // import { useSession } from "vinxi/http"; 4 + // import { eq } from "drizzle-orm"; 5 + // import { db } from "./db"; 6 + // import { Users } from "../../drizzle/schema"; 7 7 8 - function validateUsername(username: unknown) { 9 - if (typeof username !== "string" || username.length < 3) { 10 - return `Usernames must be at least 3 characters long`; 11 - } 12 - } 8 + // function validateUsername(username: unknown) { 9 + // if (typeof username !== "string" || username.length < 3) { 10 + // return `Usernames must be at least 3 characters long`; 11 + // } 12 + // } 13 13 14 - function validatePassword(password: unknown) { 15 - if (typeof password !== "string" || password.length < 6) { 16 - return `Passwords must be at least 6 characters long`; 17 - } 18 - } 14 + // function validatePassword(password: unknown) { 15 + // if (typeof password !== "string" || password.length < 6) { 16 + // return `Passwords must be at least 6 characters long`; 17 + // } 18 + // } 19 19 20 - async function login(username: string, password: string) { 21 - const user = db.select().from(Users).where(eq(Users.username, username)).get(); 22 - if (!user || password !== user.password) throw new Error("Invalid login"); 23 - return user; 24 - } 20 + // async function login(username: string, password: string) { 21 + // const user = db.select().from(Users).where(eq(Users.username, username)).get(); 22 + // if (!user || password !== user.password) throw new Error("Invalid login"); 23 + // return user; 24 + // } 25 25 26 - async function register(username: string, password: string) { 27 - const existingUser = db.select().from(Users).where(eq(Users.username, username)).get(); 28 - if (existingUser) throw new Error("User already exists"); 29 - return db.insert(Users).values({ username, password }).returning().get(); 30 - } 26 + // async function register(username: string, password: string) { 27 + // const existingUser = db.select().from(Users).where(eq(Users.username, username)).get(); 28 + // if (existingUser) throw new Error("User already exists"); 29 + // return db.insert(Users).values({ username, password }).returning().get(); 30 + // } 31 31 32 - function getSession() { 33 - return useSession({ 34 - password: process.env.SESSION_SECRET ?? "areallylongsecretthatyoushouldreplace" 35 - }); 36 - } 32 + // function getSession() { 33 + // return useSession({ 34 + // password: process.env.SESSION_SECRET ?? "areallylongsecretthatyoushouldreplace" 35 + // }); 36 + // } 37 37 38 - export async function loginOrRegister(formData: FormData) { 39 - const username = String(formData.get("username")); 40 - const password = String(formData.get("password")); 41 - const loginType = String(formData.get("loginType")); 42 - let error = validateUsername(username) || validatePassword(password); 43 - if (error) return new Error(error); 38 + // export async function loginOrRegister(formData: FormData) { 39 + // const username = String(formData.get("username")); 40 + // const password = String(formData.get("password")); 41 + // const loginType = String(formData.get("loginType")); 42 + // let error = validateUsername(username) || validatePassword(password); 43 + // if (error) return new Error(error); 44 44 45 - try { 46 - const user = await (loginType !== "login" 47 - ? register(username, password) 48 - : login(username, password)); 49 - const session = await getSession(); 50 - await session.update(d => { 51 - d.userId = user.id; 52 - }); 53 - } catch (err) { 54 - return err as Error; 55 - } 56 - throw redirect("/"); 57 - } 45 + // try { 46 + // const user = await (loginType !== "login" 47 + // ? register(username, password) 48 + // : login(username, password)); 49 + // const session = await getSession(); 50 + // await session.update(d => { 51 + // d.userId = user.id; 52 + // }); 53 + // } catch (err) { 54 + // return err as Error; 55 + // } 56 + // throw redirect("/"); 57 + // } 58 58 59 - export async function logout() { 60 - const session = await getSession(); 61 - await session.update(d => (d.userId = undefined)); 62 - throw redirect("/login"); 63 - } 59 + // export async function logout() { 60 + // const session = await getSession(); 61 + // await session.update(d => (d.userId = undefined)); 62 + // throw redirect("/login"); 63 + // } 64 64 65 - export async function getUser() { 66 - const session = await getSession(); 67 - const userId = session.data.userId; 68 - if (userId === undefined) throw redirect("/login"); 65 + // export async function getUser() { 66 + // const session = await getSession(); 67 + // const userId = session.data.userId; 68 + // if (userId === undefined) throw redirect("/login"); 69 69 70 - try { 71 - const user = db.select().from(Users).where(eq(Users.id, userId)).get(); 72 - if (!user) throw redirect("/login"); 73 - return { id: user.id, username: user.username }; 74 - } catch { 75 - throw logout(); 76 - } 77 - } 70 + // try { 71 + // const user = db.select().from(Users).where(eq(Users.id, userId)).get(); 72 + // if (!user) throw redirect("/login"); 73 + // return { id: user.id, username: user.username }; 74 + // } catch { 75 + // throw logout(); 76 + // } 77 + // }
+5 -33
src/db/index.ts
··· 1 1 import 'dotenv/config'; 2 - import { eq } from 'drizzle-orm'; 3 2 import { drizzle } from 'drizzle-orm/node-postgres'; 4 3 import { postTable } from './schema'; 5 4 6 5 const db = drizzle(process.env.DATABASE_URL!); 7 6 8 - async function main() { 9 - const post: typeof postTable.$inferInsert = { 10 - message: 'hello', 11 - author: 'etienne' 12 - }; 13 - 14 - await db.insert(postTable).values(post); 15 - console.log('New post created!') 16 - 17 - const posts = await db.select().from(postTable); 18 - console.log('Getting all posts from the database: ', posts) 19 - /* 20 - const posts: { 21 - id: number; 22 - name: string; 23 - age: number; 24 - email: string; 25 - }[] 26 - */ 27 - 28 - await db 29 - .update(postTable) 30 - .set({ 31 - message: 'oh no', 32 - }) 33 - .where(eq(postTable.author, post.author)); 34 - const updated = await db.select().from(postTable); 35 - console.log('post info updated!', updated) 36 - 37 - await db.delete(postTable).where(eq(postTable.author, post.author)); 38 - console.log('post deleted!') 7 + export const insertPost = async (message: string) => { 8 + return db.insert(postTable).values({ message, author: 'Etienne'}) 39 9 } 40 10 41 - main(); 11 + export const getPosts = async () => { 12 + return db.select().from(postTable) 13 + }
+11 -6
src/routes/index.tsx
··· 1 1 import { createAsync, type RouteDefinition } from "@solidjs/router"; 2 - import { getUser, logout } from "~/api"; 2 + import { For } from "solid-js"; 3 + import { getPosts } from "~/db"; 3 4 4 5 export const route = { 5 6 preload() { 6 - getUser(); 7 + getPosts(); 7 8 } 8 9 } satisfies RouteDefinition; 9 10 10 11 export default function Home() { 11 - const user = createAsync(async () => getUser(), { deferStream: true }); 12 + const posts = createAsync(async () => (await getPosts()).map(post => post.message || ''), { deferStream: true }); 13 + 12 14 return ( 13 15 <main class="w-full p-4 space-y-2"> 14 - <h2 class="font-bold text-3xl">Hello {user()?.username}</h2> 16 + <For each={posts()}> 17 + {(post) => (<span>{post}</span>)} 18 + </For> 19 + {/* <h2 class="font-bold text-3xl">Hello {user()?.username}</h2> */} 15 20 <h3 class="font-bold text-xl">Message board</h3> 16 - <form action={logout} method="post"> 21 + {/* <form action={logout} method="post"> 17 22 <button name="logout" type="submit"> 18 23 Logout 19 24 </button> 20 - </form> 25 + </form> */} 21 26 </main> 22 27 ); 23 28 }