Compare commits

..

2 commits

Author SHA1 Message Date
thislight
3afda89dfc
Upgrade dependencies
All checks were successful
/ depoly (push) Successful in 1m10s
* upgrade suid to v0.16
* upgrade @solidjs/router to v0.14
* upgrade nanostores to v0.11
* upgrade minor changed dependencies
2024-09-14 15:56:40 +08:00
thislight
71487dfbb3
start of 1.0.6 2024-09-14 15:19:09 +08:00
3 changed files with 28 additions and 43 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.5", "version": "1.0.6",
"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.2.0", "@suid/vite-plugin": "^0.3.0",
"@types/hammerjs": "^2.0.45", "@types/hammerjs": "^2.0.45",
"postcss": "^8.4.41", "postcss": "^8.4.45",
"prettier": "^3.3.3", "prettier": "^3.3.3",
"typescript": "^5.5.4", "typescript": "^5.6.2",
"vite": "^5.4.0", "vite": "^5.4.5",
"vite-plugin-package-version": "^1.1.0", "vite-plugin-package-version": "^1.1.0",
"vite-plugin-pwa": "^0.20.1", "vite-plugin-pwa": "^0.20.5",
"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.70.0" "wrangler": "^3.78.2"
}, },
"dependencies": { "dependencies": {
"@nanostores/persistent": "^0.9.1", "@nanostores/persistent": "^0.10.2",
"@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.11.5", "@solidjs/router": "^0.14.5",
"@suid/icons-material": "^0.7.0", "@suid/icons-material": "^0.8.0",
"@suid/material": "^0.16.0", "@suid/material": "^0.17.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.9.5", "nanostores": "^0.11.3",
"solid-js": "^1.8.20", "solid-js": "^1.8.22",
"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,7 +4,6 @@ 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 = {
@ -57,11 +56,9 @@ async function oauth2TokenViaAuthCode(app: RegisteredApp, authCode: string) {
} }
} }
export const acceptAccountViaAuthCode = action( export async function acceptAccountViaAuthCode(site: string, authCode: string) {
$accounts, const $store = $accounts;
"acceptAccount", const app = $registeredApps.get()[site];
async ($store, site: string, authCode: string) => {
const app = $registeredApps.get()[site];
if (!app) { if (!app) {
throw TypeError("application not found"); throw TypeError("application not found");
} }
@ -79,29 +76,20 @@ export const acceptAccountViaAuthCode = action(
$store.set(all); $store.set(all);
return acct; return acct;
}, }
);
export const updateAcctInf = action( export async function updateAcctInf(idx: number) {
$accounts, const o = $accounts.get();
"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;
$store.set(o); $accounts.set(o);
return inf; return inf;
}, }
);
export const signOut = action( export function signOut(predicate: (acct: Account) => boolean) {
$accounts, $accounts.set($accounts.get().filter((a) => !predicate(a)));
"signOut", }
($store, predicate: (acct: Account) => boolean) => {
$store.set($store.get().filter((a) => !predicate(a)));
},
);
export type RegisteredApp = { export type RegisteredApp = {
site: string; site: string;
@ -140,11 +128,9 @@ async function getAppAccessToken(app: RegisteredApp) {
return dict.access_token; return dict.access_token;
} }
export const getOrRegisterApp = action( export async function getOrRegisterApp(site: string, redirectUrl: string) {
$registeredApps, const $store = $registeredApps;
"getOrRegisterApp", const all = $store.get();
async ($store, site: string, redirectUrl: string) => {
const all = $store.get();
const savedApp = all[site]; const savedApp = all[site];
if (savedApp && savedApp.redirectUrl === redirectUrl) { if (savedApp && savedApp.redirectUrl === redirectUrl) {
const appAccessToken = await getAppAccessToken(savedApp); const appAccessToken = await getAppAccessToken(savedApp);
@ -198,5 +184,4 @@ export const getOrRegisterApp = action(
}; };
$store.set(all); $store.set(all);
return all[site]; return all[site];
}, }
);