add chat invite link path
This commit is contained in:
@@ -3,6 +3,7 @@ import * as path from 'node:path'
|
||||
import {fileURLToPath} from 'node:url'
|
||||
|
||||
import {AtpAgent} from '@atproto/api'
|
||||
import {type FontWeight} from 'satori'
|
||||
|
||||
import {type Config} from './config.js'
|
||||
|
||||
@@ -11,13 +12,15 @@ const __DIRNAME = path.dirname(fileURLToPath(import.meta.url))
|
||||
export type AppContextOptions = {
|
||||
cfg: Config
|
||||
appviewAgent: AtpAgent
|
||||
fonts: {name: string; data: Buffer}[]
|
||||
chatAgent: AtpAgent
|
||||
fonts: {name: string; data: Buffer; weight?: FontWeight}[]
|
||||
}
|
||||
|
||||
export class AppContext {
|
||||
cfg: Config
|
||||
appviewAgent: AtpAgent
|
||||
fonts: {name: string; data: Buffer}[]
|
||||
chatAgent: AtpAgent
|
||||
fonts: {name: string; data: Buffer; weight?: FontWeight}[]
|
||||
abortController = new AbortController()
|
||||
|
||||
private opts: AppContextOptions
|
||||
@@ -26,24 +29,40 @@ export class AppContext {
|
||||
this.opts = opts
|
||||
this.cfg = opts.cfg
|
||||
this.appviewAgent = opts.appviewAgent
|
||||
this.chatAgent = opts.chatAgent
|
||||
this.fonts = opts.fonts
|
||||
}
|
||||
|
||||
static async fromConfig(cfg: Config, overrides?: Partial<AppContextOptions>) {
|
||||
const appviewAgent = new AtpAgent({service: cfg.service.appviewUrl})
|
||||
const chatAgent = new AtpAgent({service: cfg.service.chatUrl})
|
||||
const fontDirectory = path.join(__DIRNAME, 'assets', 'fonts')
|
||||
const fontFiles = readdirSync(fontDirectory)
|
||||
const fonts = fontFiles.map(file => {
|
||||
return {
|
||||
name: path.basename(file, path.extname(file)),
|
||||
data: readFileSync(path.join(fontDirectory, file)),
|
||||
weight: getWeight(file),
|
||||
}
|
||||
})
|
||||
return new AppContext({
|
||||
cfg,
|
||||
appviewAgent,
|
||||
chatAgent,
|
||||
fonts,
|
||||
...overrides,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function getWeight(file: string): FontWeight {
|
||||
switch (path.basename(file, path.extname(file))) {
|
||||
case 'Inter-Regular':
|
||||
return 400
|
||||
case 'Inter-SemiBold':
|
||||
return 600
|
||||
case 'Inter-Bold':
|
||||
default:
|
||||
return 700
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user