mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-24 06:36:27 -08:00
Merge branch 'api-v1' into jwt
This commit is contained in:
commit
2f32644b3d
|
@ -57,14 +57,6 @@ if (config.forceSSL) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// funcs
|
|
||||||
|
|
||||||
// init data
|
|
||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
||||||
if (!fs.existsSync(__dirname + "/../.data/"))
|
|
||||||
fs.mkdirSync(__dirname + "/../.data/")
|
|
||||||
|
|
||||||
// discord
|
// discord
|
||||||
let files = new Files(config)
|
let files = new Files(config)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { readFile, writeFile, rename, readdir } from "fs/promises"
|
import { readFile, writeFile, readdir, mkdir } from "fs/promises"
|
||||||
|
import { existsSync } from "fs"
|
||||||
import path from "node:path"
|
import path from "node:path"
|
||||||
|
|
||||||
const DATADIR = `./.data`
|
const DATADIR = `./.data`
|
||||||
|
@ -92,6 +93,11 @@ export default class DbFile<Structure extends ({}|[])> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async findAvailable() {
|
private async findAvailable() {
|
||||||
|
// would it be worth it to remove existsSync here?
|
||||||
|
// mkdir seems to already do it itself when recursive is true
|
||||||
|
if (!existsSync(DATADIR))
|
||||||
|
await mkdir(DATADIR, { recursive: true })
|
||||||
|
|
||||||
return (await readdir(DATADIR))
|
return (await readdir(DATADIR))
|
||||||
.filter(e => e.match(new RegExp(`^${this.name}(?:-b)?.json$`)))
|
.filter(e => e.match(new RegExp(`^${this.name}(?:-b)?.json$`)))
|
||||||
.map(e => path.join(DATADIR, e))
|
.map(e => path.join(DATADIR, e))
|
||||||
|
|
|
@ -17,6 +17,14 @@ export const getAccount: RequestHandler = async function (ctx, next) {
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function resolveTarget(actor: Accounts.Account, targetString: string) {
|
||||||
|
return targetString == "me"
|
||||||
|
? actor
|
||||||
|
: targetString.startsWith("@")
|
||||||
|
? Accounts.getFromUsername(targetString.slice(1))
|
||||||
|
: Accounts.getFromId(targetString)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description use :user param to get a target for this route
|
* @description use :user param to get a target for this route
|
||||||
*/
|
*/
|
||||||
|
@ -29,12 +37,7 @@ export const getTarget: RequestHandler = async (ctx, next) => {
|
||||||
|
|
||||||
let actor = ctx.get("account")
|
let actor = ctx.get("account")
|
||||||
|
|
||||||
let target =
|
let target = resolveTarget(actor, ctx.req.param("user"))
|
||||||
ctx.req.param("user") == "me"
|
|
||||||
? actor
|
|
||||||
: ctx.req.param("user").startsWith("@")
|
|
||||||
? Accounts.getFromUsername(ctx.req.param("user").slice(1))
|
|
||||||
: Accounts.getFromId(ctx.req.param("user"))
|
|
||||||
|
|
||||||
if (!target) return ServeError(ctx, 404, "account does not exist")
|
if (!target) return ServeError(ctx, 404, "account does not exist")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue