mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-21 21:36:26 -08:00
prepare to switch
This commit is contained in:
parent
e93e56e8cd
commit
c85de0e86a
|
@ -161,6 +161,16 @@ export namespace files {
|
|||
}
|
||||
}
|
||||
|
||||
export type AccountResolvable = Account | string | `@${string}`
|
||||
|
||||
export function resolve(obj: AccountResolvable) {
|
||||
return typeof obj == "object"
|
||||
? obj
|
||||
: obj.startsWith("@")
|
||||
? getFromUsername(obj.slice(1))
|
||||
: getFromId(obj)
|
||||
}
|
||||
|
||||
Db.read()
|
||||
.then(() => {
|
||||
if (!Db.data.find(e => e.admin)) {
|
||||
|
|
|
@ -6,6 +6,7 @@ import { z } from "zod"
|
|||
import { AuthSchemas } from "./schemas/index.js"
|
||||
import DbFile from "./dbfile.js"
|
||||
import * as jose from "jose"
|
||||
import { AccountResolvable } from "./accounts.js"
|
||||
export let AuthTokenTO: { [key: string]: NodeJS.Timeout } = {}
|
||||
|
||||
export type TokenPermission = z.infer<typeof AuthSchemas.Scope>
|
||||
|
@ -15,17 +16,15 @@ export type AuthToken = z.infer<typeof AuthSchemas.AuthToken>
|
|||
export const Db = new DbFile<AuthToken[]>("tokens", [])
|
||||
|
||||
export function create(
|
||||
id: string,
|
||||
account: AccountResolvable,
|
||||
expire: number | null = 24 * 60 * 60 * 1000,
|
||||
type: TokenType = "User",
|
||||
tokenPermissions?: TokenPermission[],
|
||||
issuer?: string
|
||||
tokenPermissions?: TokenPermission[]
|
||||
) {
|
||||
let token = AuthSchemas.AuthToken.parse({
|
||||
account: id,
|
||||
token: crypto.randomBytes(36).toString("hex"),
|
||||
account,
|
||||
id: crypto.randomUUID(),
|
||||
expire: typeof expire == "number" ? Date.now() + expire : null,
|
||||
issuer,
|
||||
type,
|
||||
tokenPermissions:
|
||||
type != "User" ? tokenPermissions || ["user"] : undefined,
|
||||
|
|
|
@ -35,7 +35,6 @@ export const AuthToken = z.discriminatedUnion("type",[
|
|||
}),
|
||||
BaseAuthToken.extend({
|
||||
type: z.literal("App"),
|
||||
tokenPermissions: z.array(Scope).default(["user"]),
|
||||
issuer: z.string()
|
||||
tokenPermissions: z.array(Scope).default(["user"])
|
||||
})
|
||||
])
|
|
@ -114,8 +114,7 @@ export default function (files: Files) {
|
|||
"ApiKey",
|
||||
params.scopes == "all"
|
||||
? AuthSchemas.Scope.options
|
||||
: Array.from(new Set(params.scopes)),
|
||||
"monofile"
|
||||
: Array.from(new Set(params.scopes))
|
||||
)
|
||||
return ctx.text(token)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue