Optimize config endpoint
This commit is contained in:
parent
0f67adf98a
commit
486b4a329f
4 changed files with 16 additions and 13 deletions
|
@ -106,7 +106,7 @@ async function getConfig (req: express.Request, res: express.Response) {
|
|||
}
|
||||
|
||||
async function getAbout (req: express.Request, res: express.Response) {
|
||||
const { avatars, banners } = await ActorImageModel.listServerActorImages()
|
||||
const serverActor = await getServerActor()
|
||||
|
||||
const about: About = {
|
||||
instance: {
|
||||
|
@ -127,8 +127,8 @@ async function getAbout (req: express.Request, res: express.Response) {
|
|||
languages: CONFIG.INSTANCE.LANGUAGES,
|
||||
categories: CONFIG.INSTANCE.CATEGORIES,
|
||||
|
||||
banners: banners.map(b => b.toFormattedJSON()),
|
||||
avatars: avatars.map(a => a.toFormattedJSON())
|
||||
banners: serverActor.Banners.map(b => b.toFormattedJSON()),
|
||||
avatars: serverActor.Avatars.map(a => a.toFormattedJSON())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,12 +10,12 @@ import { CONFIG, isEmailEnabled } from '@server/initializers/config.js'
|
|||
import { CONSTRAINTS_FIELDS, DEFAULT_THEME_NAME, PEERTUBE_VERSION } from '@server/initializers/constants.js'
|
||||
import { isSignupAllowed, isSignupAllowedForCurrentIP } from '@server/lib/signup.js'
|
||||
import { ActorCustomPageModel } from '@server/models/account/actor-custom-page.js'
|
||||
import { getServerActor } from '@server/models/application/application.js'
|
||||
import { PluginModel } from '@server/models/server/plugin.js'
|
||||
import { Hooks } from './plugins/hooks.js'
|
||||
import { PluginManager } from './plugins/plugin-manager.js'
|
||||
import { getThemeOrDefault } from './plugins/theme-utils.js'
|
||||
import { VideoTranscodingProfilesManager } from './transcoding/default-transcoding-profiles.js'
|
||||
import { ActorImageModel } from '@server/models/actor/actor-image.js'
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -47,9 +47,9 @@ class ServerConfigManager {
|
|||
async getHTMLServerConfig (): Promise<HTMLServerConfig> {
|
||||
if (this.serverCommit === undefined) this.serverCommit = await getServerCommit()
|
||||
|
||||
const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME)
|
||||
const serverActor = await getServerActor()
|
||||
|
||||
const { avatars, banners } = await ActorImageModel.listServerActorImages()
|
||||
const defaultTheme = getThemeOrDefault(CONFIG.THEME.DEFAULT, DEFAULT_THEME_NAME)
|
||||
|
||||
return {
|
||||
client: {
|
||||
|
@ -104,8 +104,8 @@ class ServerConfigManager {
|
|||
javascript: CONFIG.INSTANCE.CUSTOMIZATIONS.JAVASCRIPT,
|
||||
css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS
|
||||
},
|
||||
avatars: avatars.map(a => a.toFormattedJSON()),
|
||||
banners: banners.map(b => b.toFormattedJSON())
|
||||
avatars: serverActor.Avatars.map(a => a.toFormattedJSON()),
|
||||
banners: serverActor.Banners.map(b => b.toFormattedJSON())
|
||||
},
|
||||
search: {
|
||||
remoteUri: {
|
||||
|
|
|
@ -20,7 +20,6 @@ import { CONFIG } from '../../initializers/config.js'
|
|||
import { LAZY_STATIC_PATHS, MIMETYPES, WEBSERVER } from '../../initializers/constants.js'
|
||||
import { SequelizeModel, buildSQLAttributes, throwIfNotValid } from '../shared/index.js'
|
||||
import { ActorModel } from './actor.js'
|
||||
import { getServerActor } from '../application/application.js'
|
||||
|
||||
@Table({
|
||||
tableName: 'actorImage',
|
||||
|
@ -124,9 +123,8 @@ export class ActorImageModel extends SequelizeModel<ActorImageModel> {
|
|||
return ActorImageModel.findAll(query)
|
||||
}
|
||||
|
||||
static async listServerActorImages () {
|
||||
const serverActor = await getServerActor()
|
||||
const promises = [ ActorImageType.AVATAR, ActorImageType.BANNER ].map(type => ActorImageModel.listByActor(serverActor, type))
|
||||
static async listActorImages (actor: MActorId) {
|
||||
const promises = [ ActorImageType.AVATAR, ActorImageType.BANNER ].map(type => ActorImageModel.listByActor(actor, type))
|
||||
|
||||
const [ avatars, banners ] = await Promise.all(promises)
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
import { getNodeABIVersion } from '@server/helpers/version.js'
|
||||
import memoizee from 'memoizee'
|
||||
import { AllowNull, Column, Default, DefaultScope, HasOne, IsInt, Table } from 'sequelize-typescript'
|
||||
import { getNodeABIVersion } from '@server/helpers/version.js'
|
||||
import { AccountModel } from '../account/account.js'
|
||||
import { ActorImageModel } from '../actor/actor-image.js'
|
||||
import { SequelizeModel } from '../shared/index.js'
|
||||
|
||||
export const getServerActor = memoizee(async function () {
|
||||
|
@ -11,6 +12,10 @@ export const getServerActor = memoizee(async function () {
|
|||
const actor = application.Account.Actor
|
||||
actor.Account = application.Account
|
||||
|
||||
const { avatars, banners } = await ActorImageModel.listActorImages(actor)
|
||||
actor.Avatars = avatars
|
||||
actor.Banners = banners
|
||||
|
||||
return actor
|
||||
}, { promise: true })
|
||||
|
||||
|
|
Loading…
Reference in a new issue