Compare commits

..

No commits in common. "3afda89dfcc71f29b508f82272982a5daae860e0" and "3ae9cffba8a33da016991e988182376f94fd1624" have entirely different histories.

3 changed files with 43 additions and 28 deletions

BIN
bun.lockb

Binary file not shown.

View file

@ -1,7 +1,7 @@
{ {
"$schema": "https://json.schemastore.org/package", "$schema": "https://json.schemastore.org/package",
"name": "tutu", "name": "tutu",
"version": "1.0.6", "version": "1.0.5",
"description": "", "description": "",
"private": true, "private": true,
"type": "module", "type": "module",
@ -14,35 +14,35 @@
"author": "Rubicon", "author": "Rubicon",
"license": "Apache-2.0", "license": "Apache-2.0",
"devDependencies": { "devDependencies": {
"@suid/vite-plugin": "^0.3.0", "@suid/vite-plugin": "^0.2.0",
"@types/hammerjs": "^2.0.45", "@types/hammerjs": "^2.0.45",
"postcss": "^8.4.45", "postcss": "^8.4.41",
"prettier": "^3.3.3", "prettier": "^3.3.3",
"typescript": "^5.6.2", "typescript": "^5.5.4",
"vite": "^5.4.5", "vite": "^5.4.0",
"vite-plugin-package-version": "^1.1.0", "vite-plugin-package-version": "^1.1.0",
"vite-plugin-pwa": "^0.20.5", "vite-plugin-pwa": "^0.20.1",
"vite-plugin-solid": "^2.10.2", "vite-plugin-solid": "^2.10.2",
"vite-plugin-solid-styled": "^0.11.1", "vite-plugin-solid-styled": "^0.11.1",
"wrangler": "^3.78.2" "wrangler": "^3.70.0"
}, },
"dependencies": { "dependencies": {
"@nanostores/persistent": "^0.10.2", "@nanostores/persistent": "^0.9.1",
"@nanostores/solid": "^0.4.2", "@nanostores/solid": "^0.4.2",
"@solid-primitives/event-listener": "^2.3.3", "@solid-primitives/event-listener": "^2.3.3",
"@solid-primitives/intersection-observer": "^2.1.6", "@solid-primitives/intersection-observer": "^2.1.6",
"@solid-primitives/resize-observer": "^2.0.26", "@solid-primitives/resize-observer": "^2.0.26",
"@solidjs/router": "^0.14.5", "@solidjs/router": "^0.11.5",
"@suid/icons-material": "^0.8.0", "@suid/icons-material": "^0.7.0",
"@suid/material": "^0.17.0", "@suid/material": "^0.16.0",
"blurhash": "^2.0.5", "blurhash": "^2.0.5",
"colorjs.io": "^0.5.2", "colorjs.io": "^0.5.2",
"date-fns": "^3.6.0", "date-fns": "^3.6.0",
"fast-average-color": "^9.4.0", "fast-average-color": "^9.4.0",
"hammerjs": "^2.0.8", "hammerjs": "^2.0.8",
"masto": "^6.8.0", "masto": "^6.8.0",
"nanostores": "^0.11.3", "nanostores": "^0.9.5",
"solid-js": "^1.8.22", "solid-js": "^1.8.20",
"solid-styled": "^0.11.1", "solid-styled": "^0.11.1",
"stacktrace-js": "^2.0.2", "stacktrace-js": "^2.0.2",
"web-animations-js": "^2.3.2" "web-animations-js": "^2.3.2"

View file

@ -4,6 +4,7 @@ import {
createRestAPIClient, createRestAPIClient,
type mastodon, type mastodon,
} from "masto"; } from "masto";
import { action } from "nanostores";
import { createMastoClientFor } from "../masto/clients"; import { createMastoClientFor } from "../masto/clients";
export type Account = { export type Account = {
@ -56,8 +57,10 @@ async function oauth2TokenViaAuthCode(app: RegisteredApp, authCode: string) {
} }
} }
export async function acceptAccountViaAuthCode(site: string, authCode: string) { export const acceptAccountViaAuthCode = action(
const $store = $accounts; $accounts,
"acceptAccount",
async ($store, site: string, authCode: string) => {
const app = $registeredApps.get()[site]; const app = $registeredApps.get()[site];
if (!app) { if (!app) {
throw TypeError("application not found"); throw TypeError("application not found");
@ -76,20 +79,29 @@ export async function acceptAccountViaAuthCode(site: string, authCode: string) {
$store.set(all); $store.set(all);
return acct; return acct;
} },
);
export async function updateAcctInf(idx: number) { export const updateAcctInf = action(
const o = $accounts.get(); $accounts,
"updateAcctInf",
async ($store, idx: number) => {
const o = $store.get();
const client = createMastoClientFor(o[idx]); const client = createMastoClientFor(o[idx]);
const inf = await client.v1.accounts.verifyCredentials(); const inf = await client.v1.accounts.verifyCredentials();
o[idx].inf = inf; o[idx].inf = inf;
$accounts.set(o); $store.set(o);
return inf; return inf;
} },
);
export function signOut(predicate: (acct: Account) => boolean) { export const signOut = action(
$accounts.set($accounts.get().filter((a) => !predicate(a))); $accounts,
} "signOut",
($store, predicate: (acct: Account) => boolean) => {
$store.set($store.get().filter((a) => !predicate(a)));
},
);
export type RegisteredApp = { export type RegisteredApp = {
site: string; site: string;
@ -128,8 +140,10 @@ async function getAppAccessToken(app: RegisteredApp) {
return dict.access_token; return dict.access_token;
} }
export async function getOrRegisterApp(site: string, redirectUrl: string) { export const getOrRegisterApp = action(
const $store = $registeredApps; $registeredApps,
"getOrRegisterApp",
async ($store, site: string, redirectUrl: string) => {
const all = $store.get(); const all = $store.get();
const savedApp = all[site]; const savedApp = all[site];
if (savedApp && savedApp.redirectUrl === redirectUrl) { if (savedApp && savedApp.redirectUrl === redirectUrl) {
@ -184,4 +198,5 @@ export async function getOrRegisterApp(site: string, redirectUrl: string) {
}; };
$store.set(all); $store.set(all);
return all[site]; return all[site];
} },
);