@@ -65,6 +65,7 @@ export const generateDefaultConfig: () => IConfig = () => ({
|
||||
},
|
||||
thirdPartyServiceIntegration: {
|
||||
xLogSiteId: '',
|
||||
githubToken: '',
|
||||
},
|
||||
clerkOptions: {
|
||||
enable: false,
|
||||
|
||||
@@ -350,7 +350,7 @@ export class ClerkOptionsDto {
|
||||
/**
|
||||
* 第三方服务集成
|
||||
*/
|
||||
@JSONSchema({ title: '第三方服务集成' })
|
||||
@JSONSchema({ title: '第三方服务信息' })
|
||||
export class ThirdPartyServiceIntegrationDto {
|
||||
@JSONSchemaPlainField('xLog SiteId', {
|
||||
description: '文章发布同步到 [xLog](https://xlog.app)',
|
||||
@@ -358,6 +358,15 @@ export class ThirdPartyServiceIntegrationDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
xLogSiteId?: string
|
||||
|
||||
@JSONSchemaPasswordField('GitHub Token', {
|
||||
description:
|
||||
'用于调用 GitHub API,获取仓库信息等;可选参数,如果没有遇到限流问题,可以不填写',
|
||||
})
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@SecretField
|
||||
githubToken?: string
|
||||
}
|
||||
|
||||
@JSONSchema({ title: '认证安全设置', 'ui:options': { type: 'hidden' } })
|
||||
|
||||
@@ -29,9 +29,17 @@ export class PageProxyService {
|
||||
* @throws {Error}
|
||||
*/
|
||||
async getAdminLastestVersionFromGHRelease(): Promise<string> {
|
||||
const { githubToken } = await this.configs.get(
|
||||
'thirdPartyServiceIntegration',
|
||||
)
|
||||
// tag_name: v3.6.x
|
||||
const { tag_name } = await fetch(
|
||||
`https://api.github.com/repos/${PKG.dashboard.repo}/releases/latest`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: githubToken || `Bearer ${githubToken}`,
|
||||
},
|
||||
},
|
||||
).then((data) => data.json())
|
||||
|
||||
return tag_name.replace(/^v/, '')
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Injectable } from '@nestjs/common'
|
||||
import { LOCAL_ADMIN_ASSET_PATH } from '~/constants/path.constant'
|
||||
import { HttpService } from '~/processors/helper/helper.http.service'
|
||||
import { spawnShell } from '~/utils'
|
||||
import { ConfigsService } from '../configs/configs.service'
|
||||
import type { Subscriber } from 'rxjs'
|
||||
import { dashboard } from '~/../package.json'
|
||||
|
||||
@@ -15,22 +16,33 @@ const { repo } = dashboard
|
||||
|
||||
@Injectable()
|
||||
export class UpdateService {
|
||||
constructor(protected readonly httpService: HttpService) {}
|
||||
constructor(
|
||||
protected readonly httpService: HttpService,
|
||||
protected readonly configService: ConfigsService,
|
||||
) {}
|
||||
downloadAdminAsset(version: string) {
|
||||
const observable$ = new Observable<string>((subscriber) => {
|
||||
;(async () => {
|
||||
const { githubToken } = await this.configService.get(
|
||||
'thirdPartyServiceIntegration',
|
||||
)
|
||||
const endpoint = `https://api.github.com/repos/${repo}/releases/tags/v${version}`
|
||||
|
||||
subscriber.next(`Getting release info from ${endpoint}.\n`)
|
||||
|
||||
const json = await fetch(endpoint)
|
||||
.then((res) => res.json())
|
||||
const result = await this.httpService.axiosRef
|
||||
.get(endpoint, {
|
||||
headers: {
|
||||
Authorization: githubToken || `Bearer ${githubToken}`,
|
||||
},
|
||||
})
|
||||
|
||||
.catch((error) => {
|
||||
subscriber.next(chalk.red(`Fetching error: ${error.message}`))
|
||||
subscriber.complete()
|
||||
return null
|
||||
})
|
||||
|
||||
const json = result?.data
|
||||
if (!json) {
|
||||
subscriber.next(chalk.red('Fetching error, json is empty. \n'))
|
||||
subscriber.complete()
|
||||
@@ -131,7 +143,14 @@ export class UpdateService {
|
||||
async getLatestAdminVersion() {
|
||||
const endpoint = `https://api.github.com/repos/${repo}/releases/latest`
|
||||
|
||||
const res = await this.httpService.axiosRef.get(endpoint)
|
||||
const { githubToken } = await this.configService.get(
|
||||
'thirdPartyServiceIntegration',
|
||||
)
|
||||
const res = await this.httpService.axiosRef.get(endpoint, {
|
||||
headers: {
|
||||
Authorization: githubToken || `Bearer ${githubToken}`,
|
||||
},
|
||||
})
|
||||
return res.data.tag_name.replace(/^v/, '')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user