Skip to content

feat: 添加推送到Bing支持 #2379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ bin/process-reporter

dist
dev/

.eslintcache
1 change: 1 addition & 0 deletions apps/core/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ ResponseInterceptor -> ResponseFilterInterceptor -> JSONTransformInterceptor ->
1. [CronService] 维护管理计划任务
- 自动备份
- 推送百度搜索
- 推送Bing搜索
- 清除缓存
- etc.
1. [EmailService] 送信服务
Expand Down
9 changes: 9 additions & 0 deletions apps/core/src/constants/error-code.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export enum ErrorCodeEnum {
// system
MasterLost = 99998,
BanInDemo = 999999,

//Bing
BingAPIFailed = 300002,
BingKeyInvalid = 300003,
BingDomainInvalid = 300004,
}

export const ErrorCode = Object.freeze<Record<ErrorCodeEnum, [string, number]>>(
Expand Down Expand Up @@ -53,5 +58,9 @@ export const ErrorCode = Object.freeze<Record<ErrorCodeEnum, [string, number]>>(
[ErrorCodeEnum.AIResultParsingError]: ['AI 结果解析错误', 500],

[ErrorCodeEnum.EmailTemplateNotFound]: ['邮件模板不存在', 400],

[ErrorCodeEnum.BingAPIFailed]: ['Bing API请求失败', 503],
[ErrorCodeEnum.BingKeyInvalid]: ['Bing API密钥无效', 401],
[ErrorCodeEnum.BingDomainInvalid]: ['Bing API域名无效', 400],
},
)
1 change: 1 addition & 0 deletions apps/core/src/modules/configs/configs.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const generateDefaultConfig: () => IConfig = () => ({
secretKey: null!,
},
baiduSearchOptions: { enable: false, token: null! },
bingSearchOptions: { enable: false, token: null! },
algoliaSearchOptions: {
enable: false,
apiKey: '',
Expand Down
16 changes: 14 additions & 2 deletions apps/core/src/modules/configs/configs.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import {
ArrayUnique,
IsBoolean,
IsEmail,
isInt,
IsInt,
IsIP,
IsNotEmpty,
IsNumber,
IsObject,
IsOptional,
IsString,
Expand Down Expand Up @@ -210,6 +208,20 @@ export class BaiduSearchOptionsDto {
token?: string
}

@JSONSchema({ title: 'Bing推送设定' })
export class BingSearchOptionsDto {
@IsOptional()
@IsBoolean()
@JSONSchemaToggleField('开启推送')
enable?: boolean

@IsOptional()
@IsString()
@SecretField
@JSONSchemaPasswordField('Bing API密钥')
token?: string
}

@JSONSchema({ title: 'Algolia Search' })
export class AlgoliaSearchOptionsDto {
@IsBoolean()
Expand Down
3 changes: 3 additions & 0 deletions apps/core/src/modules/configs/configs.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
BackupOptionsDto,
BaiduSearchOptionsDto,
BarkOptionsDto,
BingSearchOptionsDto,
CommentOptionsDto,
FeatureListDto,
FriendLinkOptionsDto,
Expand Down Expand Up @@ -67,6 +68,8 @@ export abstract class IConfig {
backupOptions: Required<BackupOptionsDto>
@ConfigField(() => BaiduSearchOptionsDto)
baiduSearchOptions: Required<BaiduSearchOptionsDto>
@ConfigField(() => BingSearchOptionsDto)
bingSearchOptions: Required<BingSearchOptionsDto>
@ConfigField(() => AlgoliaSearchOptionsDto)
algoliaSearchOptions: Required<AlgoliaSearchOptionsDto>

Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/modules/update/update.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class UpdateService {
return
}

const cdnDownloadUrl = `https://mirror.ghproxy.com/${downloadUrl}`
const cdnDownloadUrl = `https://ghfast.top/${downloadUrl}`
// const cdnDownloadUrl = downloadUrl

subscriber.next(
Expand Down
47 changes: 46 additions & 1 deletion apps/core/src/processors/helper/helper.cron.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { ConfigsService } from '~/modules/configs/configs.service'
import { InjectModel } from '~/transformers/model.transformer'
import { getRedisKey } from '~/utils/redis.util'

import { CacheService } from '../redis/cache.service'
import { RedisService } from '../redis/redis.service'
import { HttpService } from './helper.http.service'
import { JWTService } from './helper.jwt.service'
Expand Down Expand Up @@ -160,6 +159,52 @@ export class CronService {
return null
}

@CronOnce(CronExpression.EVERY_DAY_AT_1AM, { name: 'pushToBingSearch' })
@CronDescription('推送到Bing')
async pushToBingSearch() {
const {
url: { webUrl },
bingSearchOptions: configs,
} = await this.configs.waitForConfigReady()

if (!configs.enable) {
return
}
const apiKey = configs.token
if (!apiKey) {
this.logger.error('[BingSearchPushTask] API key 为空')
return
}

const pushUrls = await this.aggregateService.getSiteMapContent()
const urls = pushUrls.map((item) => item.url)

try {
const res = await this.http.axiosRef.post(
`https://ssl.bing.com/webmaster/api.svc/json/SubmitUrlbatch?apikey=${apiKey}`,
{
siteUrl: webUrl,
urlList: urls,
},
{
headers: {
'Content-Type': 'application/json',
charset: 'utf-8',
},
},
)
if (res?.data?.d === null) {
this.logger.log('Bing站长提交成功')
} else {
this.logger.log(`Bing站长提交结果:${JSON.stringify(res.data)}`)
}
return res.data
} catch (error) {
this.logger.error(`Bing推送错误:${error.message}`)
}
return null
}

@CronDescription('扫表:删除过期 JWT')
@CronOnce(CronExpression.EVERY_DAY_AT_1AM, {
name: 'deleteExpiredJWT',
Expand Down
5 changes: 5 additions & 0 deletions packages/api-client/models/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export declare class BaiduSearchOptionsModel {
enable: boolean
token?: string
}
export declare class BingSearchOptionsModel {
enable: boolean
token?: string
}

export declare class AlgoliaSearchOptionsModel {
enable: boolean
apiKey?: string
Expand Down
2 changes: 1 addition & 1 deletion scripts/server-deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const { homedir } = os
const { repository } = require('../package.json')

const argv = process.argv.slice(2)
const scpPath = av['scp_path']
const scpPath = av.scp_path
function getOsBuildAssetName() {
return `release-linux.zip`
}
Expand Down
Loading