1
0
mirror of https://github.com/ialley-workshop-open/uni-halo.git synced 2026-11-13 22:11:42 +08:00

chore: 批量新增项目依赖、工具函数、页面与组件资源

1. 新增mp-html、qs等生产依赖,补全项目基础库
2. 新增平台判断、缓存、工具函数等通用工具集
3. 新增标签页、网站浏览页、关于页等业务页面
4. 新增分类卡片、通知弹窗等业务组件
5. 新增uts-progressNotification、liu-poster、uhalo-upgrade等uni模块
6. 补充audio/video组件样式补件,修复uni-components路径缺失问题
7. 新增环境变量Halo个人令牌配置项
8. 重构store导出结构,新增appConfig/halo/setting三个状态模块
9. 新增tsconfig编译目标配置,适配更高版本ES语法
This commit is contained in:
小莫唐尼
2026-08-31 19:56:16 +08:00
parent ba5b77568b
commit 067f3ed98a
147 changed files with 20866 additions and 325 deletions
+299
View File
@@ -0,0 +1,299 @@
/**
* Halo 官方 API 接口定义
* 覆盖官方扩展点:api.content.halo.run / api.halo.run / api.moment.halo.run /
* api.photo.halo.run / api.link.halo.run / api.plugin.halo.run
* 风格参考 src/api/foo-alova.ts:http.Get<IResponse<T>>(url, { params, header, meta })
* 源自旧项目 api/v2/all.api.js(官方部分),按需命名导出
*/
import { http } from '@/http/alova';
import { RequestFrom } from '@/http/tools/enum';
import type { IResponse } from '@/http/types';
import { getCache } from '@/utils/storage';
import { getNologinEmail, getOpenid } from '@/utils/auth';
import type {
IBlogStats,
ICategory,
ICategoryListReq,
ICategoryListRes,
IComment,
ICommentListReq,
ICommentListRes,
ILink,
ILinkGroupListRes,
ILinkListRes,
IMoment,
IMomentListReq,
IMomentListRes,
IPhotoGroupListReq,
IPhotoGroupListRes,
IPhotoListReq,
IPhotoListRes,
IPluginAvailable,
IPost,
IPostListReq,
IPostListRes,
ISearchReq,
ISearchRes,
ITagListRes,
ITrackerCounterReq,
IUpvoteReq
} from './types/halo';
/** 评论验证码 cookie key */
const COMMENT_WIDGET_CAPTCHA_COOKIES = 'comment-widget-captcha';
/* ==================== 文章 ==================== */
/**
* 文章列表
*/
export function getPostList(params: IPostListReq) {
return http.Get<IResponse<IPostListRes>>('/apis/api.content.halo.run/v1alpha1/posts', {
query: params,
meta: { requestFrom: RequestFrom.Halo }
});
}
/**
* 文章详情(带访客标识头)
*/
export function getPostByName(name: string) {
return http.Get<IResponse<IPost>>(`/apis/api.content.halo.run/v1alpha1/posts/${name}`, {
headers: {
'Wechat-Session-Id': getOpenid(),
'nologin-email': getNologinEmail()
},
meta: { requestFrom: RequestFrom.Halo }
});
}
/**
* 关键词搜索文章
*/
export function getPostListByKeyword(params: ISearchReq) {
return http.Post<IResponse<ISearchRes>>('/apis/api.halo.run/v1alpha1/indices/-/search', params, {
meta: { requestFrom: RequestFrom.Halo }
});
}
/* ==================== 分类 / 标签 ==================== */
/**
* 分类列表
* 注:旧代码用 qs.stringify 特殊序列化(arrayFormat:'repeat'、allowDots),
* alova 的 params 对数组默认即 repeat 形式(a=1&a=2),已等价;如遇嵌套对象场景再单独处理
*/
export function getCategoryList(params: ICategoryListReq) {
return http.Get<IResponse<ICategoryListRes>>('/apis/api.content.halo.run/v1alpha1/categories', {
params,
meta: { requestFrom: RequestFrom.Halo }
});
}
/**
* 分类下文章列表
*/
export function getCategoryPostList(name: string, params: IPostListReq) {
return http.Get<IResponse<IPostListRes>>(`/apis/api.content.halo.run/v1alpha1/categories/${name}/posts`, {
params,
meta: { requestFrom: RequestFrom.Halo }
});
}
/**
* 标签列表
*/
export function getTagList(params: ICategoryListReq) {
return http.Get<IResponse<ITagListRes>>('/apis/api.content.halo.run/v1alpha1/tags', {
params,
meta: { requestFrom: RequestFrom.Halo }
});
}
/**
* 标签下文章列表
*/
export function getPostByTagName(tagName: string, params: IPostListReq) {
return http.Get<IResponse<IPostListRes>>(`/apis/api.content.halo.run/v1alpha1/tags/${tagName}/posts`, {
params,
meta: { requestFrom: RequestFrom.Halo }
});
}
/* ==================== 评论(含验证码 cookie 链路) ==================== */
/**
* 评论列表
*/
export function getPostCommentList(params: ICommentListReq) {
return http.Get<IResponse<ICommentListRes>>('/apis/api.halo.run/v1alpha1/comments', {
params,
meta: { requestFrom: RequestFrom.Halo }
});
}
/**
* 评论回复列表
*/
export function getPostCommentReplyList(commentName: string, params: ICommentListReq) {
return http.Get<IResponse<ICommentListRes>>(`/apis/api.halo.run/v1alpha1/comments/${commentName}/reply`, {
params,
meta: { requestFrom: RequestFrom.Halo }
});
}
/** 新增评论(带验证码,captchaCode 转入请求头) */
export interface IAddCommentReq {
raw: string;
content?: string;
owner?: Record<string, unknown>;
/** 评论目标引用(subjectRef: group/kind/name/version) */
subjectRef?: {
group: string;
kind: string;
name: string;
version?: string;
};
/** 验证码,提交时转入 X-Captcha-Code 头 */
captchaCode?: string;
}
/**
* 新增评论(captchaCode 拆出转 X-Captcha-Code 头 + Cookie)
*/
export function addPostComment(data: IAddCommentReq) {
const { captchaCode, ...rest } = data;
const headers: Record<string, string> = {
Accept: 'application/json'
};
if (captchaCode) headers['X-Captcha-Code'] = captchaCode;
const cookie = getCache<string>(COMMENT_WIDGET_CAPTCHA_COOKIES);
if (cookie) headers.Cookie = cookie;
return http.Post<IResponse<IComment>>('/apis/api.halo.run/v1alpha1/comments', rest, {
headers,
meta: { requestFrom: RequestFrom.Halo }
});
}
/**
* 新增评论回复(同上,验证码逻辑)
*/
export function addPostCommentReply(commentName: string, data: IAddCommentReq) {
const { captchaCode, ...rest } = data;
const headers: Record<string, string> = {
Accept: 'application/json'
};
if (captchaCode) headers['X-Captcha-Code'] = captchaCode;
const cookie = getCache<string>(COMMENT_WIDGET_CAPTCHA_COOKIES);
if (cookie) headers.Cookie = cookie;
return http.Post<IResponse<IComment>>(`/apis/api.halo.run/v1alpha1/comments/${commentName}/reply`, rest, {
headers,
meta: { requestFrom: RequestFrom.Halo }
});
}
/* ==================== 瞬间 ==================== */
/**
* 瞬间列表
*/
export function getMomentList(params: IMomentListReq) {
return http.Get<IResponse<IMomentListRes>>('/apis/api.moment.halo.run/v1alpha1/moments', {
params,
meta: { requestFrom: RequestFrom.Halo }
});
}
/**
* 瞬间详情
*/
export function getMomentByName(name: string) {
return http.Get<IResponse<IMoment>>(`/apis/api.moment.halo.run/v1alpha1/moments/${name}`, {
meta: { requestFrom: RequestFrom.Halo }
});
}
/* ==================== 图库 ==================== */
/**
* 相册分组列表
*/
export function getPhotoGroupList(params: IPhotoGroupListReq) {
return http.Get<IResponse<IPhotoGroupListRes>>('/apis/api.photo.halo.run/v1alpha1/photogroups', {
params,
meta: { requestFrom: RequestFrom.Halo }
});
}
/**
* 照片列表(按相册)
*/
export function getPhotoListByGroupName(params: IPhotoListReq) {
return http.Get<IResponse<IPhotoListRes>>('/apis/api.photo.halo.run/v1alpha1/photos', {
params,
meta: { requestFrom: RequestFrom.Halo }
});
}
/* ==================== 友链 ==================== */
/**
* 友链分组列表
*/
export function getFriendLinkGroupList(params: ICategoryListReq) {
return http.Get<IResponse<ILinkGroupListRes>>('/apis/api.link.halo.run/v1alpha1/linkgroups', {
params,
meta: { requestFrom: RequestFrom.Halo }
});
}
/**
* 友链列表
*/
export function getFriendLinkList(params: ICategoryListReq) {
return http.Get<IResponse<ILinkListRes>>('/apis/api.link.halo.run/v1alpha1/links', {
params,
meta: { requestFrom: RequestFrom.Halo }
});
}
/* ==================== 统计 / 埋点 / 插件 ==================== */
/**
* 博客统计信息
*/
export function getBlogStatistics() {
return http.Get<IResponse<IBlogStats>>('/apis/api.halo.run/v1alpha1/stats/-', {
meta: { requestFrom: RequestFrom.Halo }
});
}
/**
* 提交点赞
*/
export function submitUpvote(data: IUpvoteReq) {
return http.Post<IResponse<unknown>>('/apis/api.halo.run/v1alpha1/trackers/upvote', data, {
meta: { requestFrom: RequestFrom.Halo }
});
}
/**
* 提交计数埋点
*/
export function postTrackersCounter(data: ITrackerCounterReq) {
return http.Post<IResponse<unknown>>('/apis/api.halo.run/v1alpha1/trackers/counter', data, {
meta: { requestFrom: RequestFrom.Halo }
});
}
/**
* 检查插件是否可用
*/
export function checkPluginAvailable(name: string) {
return http.Get<IResponse<IPluginAvailable>>(`/apis/api.plugin.halo.run/v1alpha1/plugins/${name}/available`, {
meta: { requestFrom: RequestFrom.Halo }
});
}
/** 分类资源(供加密分类判断等场景) */
export type { ICategory, ILink, IMoment, IPost };
+432
View File
@@ -0,0 +1,432 @@
/**
* Halo 官方 API 类型定义
* 对应 src/api/halo.ts(Halo 官方 api.*.halo.run 扩展点)
* 结构基于 Halo 2.x API 规范
*/
/** Halo 通用元数据 */
export interface IMetadata {
name: string
labels?: Record<string, string>
annotations?: Record<string, string>
version?: number
creationTimestamp?: string
updateTimestamp?: string
}
/** Halo 通用分页结构(ListResult) */
export interface IListResult<T> {
page: number
size: number
total: number
items: T[]
first: boolean
last: boolean
hasNext: boolean
hasPrevious: boolean
totalPages: number
}
/* ---------- 文章 Post ---------- */
export interface IPostSpec {
title: string
slug: string
excerpt?: string
cover?: string
/** 发布时间(Halo 2.x 结构,旧项目直接使用) */
publishTime?: string
deleted: boolean
publish: boolean
pinned: boolean
allowComment: boolean
visible: 'PUBLIC' | 'PRIVATE'
priority: number
categories: string[]
tags: string[]
template?: string
htmlMetas?: Record<string, string>
baseSnapshot?: string
headSnapshot?: string
snapshotVersion?: number
excerptAutoGenerate?: boolean
}
export interface IPostStatus {
permalink: string
inProgress: boolean
commentsCount?: number
contributors?: IContributor[]
stats?: IPostStats
excerpt?: string
}
export interface IContributor {
name: string
displayName: string
avatar: string
}
export interface IPostStats {
visits?: number
upvotes?: number
comments?: number
}
/** 文章内容(含受限阅读的 raw 源文本) */
export interface IContent {
raw: string
content: string
displayVersion?: string
}
export interface IPost {
metadata: IMetadata
spec: IPostSpec
status?: IPostStatus
content?: IContent
categories?: ICategory[]
tags?: ITag[]
contributors?: IContributor[]
/** 旧项目使用的顶层统计(兼容 Halo 旧版结构) */
stats?: {
visit?: number
upvote?: number
comment?: number
[key: string]: unknown
}
}
/** 文章列表请求参数(分页 + 过滤) */
export interface IPostListReq {
page?: number
size?: number
sort?: string[]
keyword?: string
category?: string
tag?: string
visible?: 'PUBLIC' | 'PRIVATE'
[key: string]: unknown
}
export type IPostListRes = IListResult<IPost>
/** 文章搜索请求参数(关键字) */
export interface ISearchReq {
keyword?: string
page?: number
size?: number
highlightPreTag?: string
highlightPostTag?: string
}
export type ISearchRes = IListResult<IPost>
/* ---------- 分类 Category ---------- */
export interface ICategory {
metadata: IMetadata
spec: {
displayName: string
slug: string
description?: string
cover?: string
template?: string
priority: number
children?: string[]
}
status?: {
permalink: string
postCount?: number
visiblePostCount?: number
}
children?: ICategory[]
/** 文章数(旧项目首页直接读取/排序用) */
postCount?: number
}
export interface ICategoryListReq {
page?: number
size?: number
sort?: string[]
tree?: boolean
[key: string]: unknown
}
export type ICategoryListRes = IListResult<ICategory>
/** 分类下文章列表请求 */
export interface ICategoryPostListReq extends IPostListReq {
/** 私密分类密码(加密分类访问) */
password?: string
}
export type ICategoryPostListRes = IListResult<IPost>
/* ---------- 标签 Tag ---------- */
export interface ITag {
metadata: IMetadata
spec: {
displayName: string
slug: string
color?: string
cover?: string
}
status?: {
permalink: string
postCount?: number
visiblePostCount?: number
}
}
export interface ITagListReq {
page?: number
size?: number
sort?: string[]
[key: string]: unknown
}
export type ITagListRes = IListResult<ITag>
/* ---------- 评论 Comment ---------- */
export interface ICommentOwner {
kind: 'EMAIL' | 'PHONE' | 'GRAVATAR' | 'WEIXIN' | 'QQ'
displayName: string
avatar?: string
email?: string
website?: string
}
export interface IComment {
metadata: IMetadata
spec: {
raw: string
content: string
owner: ICommentOwner
userAgent?: string
ipAddress?: string
priority?: number
top?: boolean
allowNotification?: boolean
approved: boolean
hidden: boolean
subjectRef: {
group: string
version: string
kind: string
name: string
}
lastReadTime?: string
creationTime?: string
}
status?: {
hasReply?: boolean
replyCount?: number
visibleTime?: string
}
replies?: ICommentReply[]
}
export interface ICommentReply {
metadata: IMetadata
spec: {
raw: string
content: string
owner: ICommentOwner
quoteReply?: string
userAgent?: string
ipAddress?: string
priority?: number
top?: boolean
approved: boolean
hidden: boolean
subjectRef: {
group: string
version: string
kind: string
name: string
}
lastReadTime?: string
creationTime?: string
}
}
export interface ICommentListReq {
page?: number
size?: number
sort?: string[]
/** 主题名称(文章 name) */
name?: string
[key: string]: unknown
}
export type ICommentListRes = IListResult<IComment>
/* ---------- 瞬间 Moment ---------- */
export interface IMoment {
metadata: IMetadata
spec: {
content: string
owner: {
displayName: string
avatar?: string
website?: string
}
visible: 'PUBLIC' | 'PRIVATE'
allowComment: boolean
approved: boolean
pinned?: boolean
priority?: number
tags?: string[]
releaseTime?: string
}
status?: {
permalink: string
approved?: boolean
inProgress?: boolean
commentsCount?: number
}
}
export interface IMomentListReq {
page?: number
size?: number
sort?: string[]
[key: string]: unknown
}
export type IMomentListRes = IListResult<IMoment>
/* ---------- 图库 Photo ---------- */
export interface IPhotoGroup {
metadata: IMetadata
spec: {
displayName: string
description?: string
priority?: number
cover?: string
}
status?: {
permalink?: string
photoCount?: number
}
}
export interface IPhoto {
metadata: IMetadata
spec: {
displayName: string
description?: string
url: string
/** 封面图(部分接口返回,兼容旧代码) */
cover?: string
priority?: number
takeTime?: string
location?: string
latitude?: number
longitude?: number
}
}
export interface IPhotoGroupListReq {
page?: number
size?: number
sort?: string[]
[key: string]: unknown
}
export type IPhotoGroupListRes = IListResult<IPhotoGroup>
export interface IPhotoListReq {
page?: number
size?: number
sort?: string[]
groupName?: string
[key: string]: unknown
}
export type IPhotoListRes = IListResult<IPhoto>
/* ---------- 友链 FriendLink ---------- */
export interface ILinkGroup {
metadata: IMetadata
spec: {
displayName: string
priority?: number
description?: string
}
}
export interface ILink {
metadata: IMetadata
spec: {
displayName: string
url: string
logo: string
description?: string
priority?: number
groupName?: string
}
}
export interface ILinkGroupListReq {
page?: number
size?: number
sort?: string[]
[key: string]: unknown
}
export type ILinkGroupListRes = IListResult<ILinkGroup>
export interface ILinkListReq {
page?: number
size?: number
sort?: string[]
[key: string]: unknown
}
export type ILinkListRes = IListResult<ILink>
/* ---------- 统计 / 埋点 ---------- */
export interface IBlogStats {
visit?: number
upvote?: number
comment?: number
post?: number
category?: number
tag?: number
[key: string]: unknown
}
export interface ITrackerCounterReq {
group: string
name: string
plural?: string
endpoint?: string
hostname?: string
screen?: string
title?: string
referrer?: string
language?: string
/** 访问页面路径(旧项目埋点 url 字段) */
url?: string
}
export interface IUpvoteReq {
group: string
name: string
plural?: string
}
/* ---------- 插件可用性 ---------- */
export interface IPluginAvailable {
available: boolean
reason?: string
}
+313
View File
@@ -0,0 +1,313 @@
/**
* plugin-uni-halo 自定义接口 / 三方插件 API 类型定义
* 对应 src/api/uni-halo.ts(plugin-uni-halo 自身接口 + 三方插件)
*/
/* ---------- plugin-uni-halo 应用配置 ---------- */
/** 图片相关配置 */
export interface IImagesConfig {
defaultThumbnailUrl?: string
defaultStaticThumbnailUrl?: string
defaultImageUrl?: string
defaultAvatarUrl?: string
[key: string]: unknown
}
/** 插件配置(toolsPlugin/linksSubmitPlugin 等带 Authorization) */
export interface IPluginConfig {
votePlugin?: Record<string, unknown>
toolsPlugin?: { Authorization?: string } & Record<string, unknown>
linksPlugin?: Record<string, unknown>
linksSubmitPlugin?: { Authorization?: string } & Record<string, unknown>
doubanPlugin?: { position?: string } & Record<string, unknown>
[key: string]: unknown
}
/** 首页配置(banner 等) */
export interface IBannerConfig {
enabled?: boolean
showTitle?: boolean
showIndicator?: boolean
height?: string
dotPosition?: string
type?: string
list?: unknown[]
}
export interface IPageConfig {
homeConfig?: {
pageTitle?: string
useCategory?: boolean
/** 是否显示快捷导航(首页) */
useQuickNavigation?: boolean
bannerConfig?: IBannerConfig
}
categoryConfig?: { type?: string }
momentConfig?: { useTagRandomColor?: boolean }
galleryConfig?: { pageTitle?: string }
aboutConfig?: {
bgImageUrl?: string
waveImageUrl?: string
}
[key: string]: unknown
}
/** 审计模式配置 */
export interface IAuditConfig {
auditModeEnabled?: boolean
auditModeData?: {
jsonUrl?: string
jsonData?: string
}
}
/** 应用基础配置(对应旧 DefaultAppConfigs) */
export interface IAppConfig {
basicConfig?: {
tokenConfig?: {
personalToken?: string
}
}
loveConfig?: Record<string, unknown>
imagesConfig?: IImagesConfig
authorConfig?: Record<string, unknown>
appConfig?: Record<string, unknown>
pluginConfig?: IPluginConfig
pageConfig?: IPageConfig
auditConfig?: IAuditConfig
[key: string]: unknown
}
/** Halo 全局配置(对应旧 DefaultHaloGlobalConfigs,/actuator/globalinfo) */
export interface IHaloGlobalConfig {
allowAnonymousComments?: boolean
allowRegistration?: boolean
mustVerifyEmailOnRegistration?: boolean
mustVerifyPhoneOnRegistration?: boolean
restrictRegistrationDomain?: boolean
shopDisabled?: boolean
[key: string]: unknown
}
/** 审计模式模拟数据 */
export type IMockJson = Record<string, unknown>
/* ---------- plugin-uni-halo 二维码 / 检查更新 ---------- */
export interface IQRCodeInfo {
[key: string]: unknown
}
export interface IQRCodeImg {
[key: string]: unknown
}
/** 检查更新结果(uhalo-upgrade 对接) */
export interface IUpdateCheckRes {
code: number
message: string
url?: string
title?: string
contents?: string
is_mandatory?: boolean
is_silently?: boolean
type?: 'wgt' | 'apk' | 'ipa'
platform?: string[]
version?: string
[key: string]: unknown
}
/* ---------- 受限阅读(tools.muyin.site) ---------- */
export type RestrictReadType = 'password' | 'code' | 'login' | 'pay' | 'comment'
/** 受限阅读校验请求 */
export interface IRestrictReadCheckReq {
code: string
templateType: 'post'
restrictType: RestrictReadType
keyId: string
}
export interface IRestrictReadCheckRes {
success?: boolean
[key: string]: unknown
}
/** 验证码创建结果 */
export interface IVerificationCodeRes {
code?: string
[key: string]: unknown
}
/* ---------- 友链提交(linkssubmit.muyin.site) ---------- */
export interface ISubmitLinkForm {
name?: string
url?: string
logo?: string
description?: string
email?: string
[key: string]: unknown
}
export interface ILinkSubmitRes {
success?: boolean
message?: string
[key: string]: unknown
}
/* ---------- 投票(api.vote.kunkunyu.com) ---------- */
export interface IVoteListReq {
page?: number
size?: number
[key: string]: unknown
}
export interface IVoteItem {
name: string
title: string
description?: string
[key: string]: unknown
}
export type IVoteListRes = IVoteItem[]
export interface IVote {
name: string
title: string
description?: string
options?: IVoteOption[]
[key: string]: unknown
}
export interface IVoteOption {
name?: string
label?: string
count?: number
[key: string]: unknown
}
export interface IVoteUser {
[key: string]: unknown
}
export type IVoteUserListRes = IVoteUser[]
/** 提交投票 */
export interface IVoteSubmitReq {
optionName?: string
[key: string]: unknown
}
export interface IVoteSubmitRes {
success?: boolean
[key: string]: unknown
}
/* ---------- 豆瓣(api.douban.moony.la) ---------- */
export interface IDoubanDetail {
title?: string
poster?: string
rating?: string
year?: string
[key: string]: unknown
}
/* ---------- 评论组件(api.commentwidget.halo.run) ---------- */
export interface ICommentWidgetConfig {
[key: string]: unknown
}
/** 评论验证码 */
export interface ICommentCaptcha {
[key: string]: unknown
}
/* ---------- 恋爱模块(plugin-uni-halo love) ---------- */
export interface ILoveConfig {
/** 纪念日 */
anniversary?: string
/** 恋人信息 */
lovers?: {
name?: string
avatar?: string
[key: string]: unknown
}
[key: string]: unknown
}
export interface ILoveAlbum {
name?: string
title?: string
/** 相册展示名(接口返回 displayName) */
displayName?: string
description?: string
locked?: boolean
cover?: string
photos?: ILovePhoto[]
[key: string]: unknown
}
export interface ILovePhoto {
url?: string
description?: string
[key: string]: unknown
}
export interface ILoveAlbumListReq {
page?: number
size?: number
[key: string]: unknown
}
export type ILoveAlbumListRes = ILoveAlbum[]
export interface ILoveAlbumDetailReq {
[key: string]: unknown
}
export interface IUnlockAlbumReq {
password: string
}
export interface ILoveUnlockRes {
success?: boolean
[key: string]: unknown
}
export interface ILoveDailyItem {
id?: string
content?: string
date?: string
[key: string]: unknown
}
export interface ILoveDailyItemListReq {
page?: number
size?: number
[key: string]: unknown
}
export type ILoveDailyItemListRes = ILoveDailyItem[]
export interface ILoveStory {
id?: string
title?: string
content?: string
date?: string
[key: string]: unknown
}
export interface ILoveStoryListReq {
page?: number
size?: number
[key: string]: unknown
}
export type ILoveStoryListRes = ILoveStory[]
+360
View File
@@ -0,0 +1,360 @@
/**
* uni-halo 自定义 API 接口定义
* 覆盖 plugin-uni-halo(/apis/api.unihalo.ialley.cn)与三方插件接口:
* 受限阅读(tools.muyin.site)、友链提交(linkssubmit.muyin.site)、投票(api.vote.kunkunyu.com)、
* 豆瓣(api.douban.moony.la)、评论组件(api.commentwidget.halo.run)
* 风格参考 src/api/foo-alova.ts:http.Get<IResponse<T>>(url, { params, header, meta })
* 源自旧项目 api/v2/all.config.js、all.api.js(三方部分)、love.*.js,按需命名导出
*/
import { http } from '@/http/alova'
import { RequestFrom } from '@/http/tools/enum'
import type { IResponse } from '@/http/types'
import { getCache } from '@/utils/storage'
import { getNologinEmail, getOpenid } from '@/utils/auth'
import { getPersonalToken } from '@/store/token'
import type {
IAppConfig,
ICommentWidgetConfig,
IDoubanDetail,
IHaloGlobalConfig,
ILoveAlbum,
ILoveAlbumListReq,
ILoveAlbumListRes,
ILoveConfig,
ILoveDailyItem,
ILoveDailyItemListReq,
ILoveDailyItemListRes,
ILoveStory,
ILoveStoryListReq,
ILoveStoryListRes,
IQRCodeInfo,
IRestrictReadCheckReq,
IRestrictReadCheckRes,
ISubmitLinkForm,
IUpdateCheckRes,
IVote,
IVoteListReq,
IVoteListRes,
IVoteSubmitReq,
RestrictReadType,
} from './types/uni-halo'
/** 评论验证码 cookie key */
const COMMENT_WIDGET_CAPTCHA_COOKIES = 'comment-widget-captcha'
/* ==================== plugin-uni-halo 配置 ==================== */
/**
* 获取应用配置
*/
export function getAppConfigs() {
return http.Get<IResponse<IAppConfig>>('/apis/api.unihalo.ialley.cn/v1alpha1/plugins/plugin-uni-halo/getConfigs', {
meta: { requestFrom: RequestFrom.Halo },
})
}
/**
* 获取 Halo 全局配置信息
*/
export function getHaloGlobalInfo() {
return http.Get<IResponse<IHaloGlobalConfig>>('/actuator/globalinfo', {
meta: { requestFrom: RequestFrom.Halo },
})
}
/**
* 获取评论组件配置
*/
export function getCommentWidgetConfig() {
return http.Get<IResponse<ICommentWidgetConfig>>('/apis/api.commentwidget.halo.run/v1alpha1/config', {
meta: { requestFrom: RequestFrom.Halo },
})
}
/**
* 检查更新(uhalo-upgrade 插件对接,插件本体引入后业务侧入口)
*/
export function checkVersion(baseUrl: string) {
return http.Get<IResponse<IUpdateCheckRes>>('/apis/api.unihalo.ialley.cn/v1alpha1/plugins/plugin-uni-halo/checkVersion', {
params: { baseUrl },
meta: { requestFrom: RequestFrom.Halo },
})
}
/**
* 获取二维码信息
*/
export function getQRCodeInfo(key: string) {
return http.Get<IResponse<IQRCodeInfo>>(`/apis/api.unihalo.ialley.cn/v1alpha1/plugins/plugin-uni-halo/getQRCodeInfo/${key}`, {
meta: { requestFrom: RequestFrom.Halo },
})
}
/**
* 获取文章二维码图片
*/
export function getQRCodeImg(postId: string) {
return http.Get<IResponse<unknown>>(`/apis/api.unihalo.ialley.cn/v1alpha1/plugins/plugin-uni-halo/getQRCodeImg/${postId}`, {
meta: { requestFrom: RequestFrom.Halo },
})
}
/* ==================== 恋爱模块 ==================== */
/**
* 获取恋爱配置(纪念日 + 恋人信息)
*/
export function getLoveConfig() {
return http.Get<IResponse<ILoveConfig>>('/apis/api.unihalo.ialley.cn/v1alpha1/plugins/plugin-uni-halo/love-config', {
meta: { requestFrom: RequestFrom.Halo },
})
}
/**
* 获取恋爱相册列表
*/
export function getLoveAlbums(params: ILoveAlbumListReq) {
return http.Get<IResponse<ILoveAlbumListRes>>('/apis/api.unihalo.ialley.cn/v1alpha1/plugins/plugin-uni-halo/love-albums', {
params,
meta: { requestFrom: RequestFrom.Halo },
})
}
/**
* 获取恋爱相册详情
*/
export function getLoveAlbumByName(name: string, params: ILoveAlbumListReq) {
return http.Get<IResponse<ILoveAlbum>>(`/apis/api.unihalo.ialley.cn/v1alpha1/plugins/plugin-uni-halo/love-albums/${name}`, {
params,
meta: { requestFrom: RequestFrom.Halo },
})
}
/**
* 密码解锁相册
*/
export function unlockAlbum(name: string, password: string) {
return http.Post<IResponse<{ token: string, photos?: unknown[] }>>(
`/apis/api.unihalo.ialley.cn/v1alpha1/plugins/plugin-uni-halo/love-albums/${name}/unlock`,
{
password,
},
{
meta: { requestFrom: RequestFrom.Halo },
},
)
}
/**
* 获取恋爱清单列表(分页)
*/
export function getLoveDailyItems(params: ILoveDailyItemListReq) {
return http.Get<IResponse<ILoveDailyItemListRes>>(
'/apis/api.unihalo.ialley.cn/v1alpha1/plugins/plugin-uni-halo/love-daily-items',
{
params,
meta: { requestFrom: RequestFrom.Halo },
},
)
}
/**
* 获取恋爱故事列表
*/
export function getLoveStories(params: ILoveStoryListReq) {
return http.Get<IResponse<ILoveStoryListRes>>('/apis/api.unihalo.ialley.cn/v1alpha1/plugins/plugin-uni-halo/love-stories', {
params,
meta: { requestFrom: RequestFrom.Halo },
})
}
/* ==================== 受限阅读(tools.muyin.site) ==================== */
/**
* 受限阅读检查(密码/验证码/登录/付费/评论)
*/
export function requestRestrictReadCheck(restrictType: RestrictReadType, code: string, keyId: string) {
const data: IRestrictReadCheckReq = {
code,
templateType: 'post',
restrictType,
keyId,
}
return http.Post<IResponse<IRestrictReadCheckRes>>('/apis/tools.muyin.site/v1alpha1/restrict-read/check', data, {
headers: {
'Authorization': getToolsAuthorization(),
'Wechat-Session-Id': getOpenid(),
'nologin-email': getNologinEmail(),
},
meta: { requestFrom: RequestFrom.Halo },
})
}
/**
* 创建验证码(受限阅读)
*/
export function createVerificationCode() {
return http.Get<IResponse<string>>('/apis/tools.muyin.site/v1alpha1/restrict-read/create', {
headers: {
'Authorization': getToolsAuthorization(),
'Wechat-Session-Id': getOpenid(),
},
meta: { requestFrom: RequestFrom.Halo },
})
}
/* ==================== 友链提交(linkssubmit.muyin.site) ==================== */
/**
* 提交友链
*/
export function submitLink(form: ISubmitLinkForm) {
return http.Post<IResponse<{ msg?: string, message?: string }>>('/apis/linkssubmit.muyin.site/v1alpha1/submit', form, {
headers: {
'Authorization': getLinksSubmitAuthorization(),
'Wechat-Session-Id': getOpenid(),
},
meta: { requestFrom: RequestFrom.Halo },
})
}
/* ==================== 投票(api.vote.kunkunyu.com) ==================== */
/**
* 投票列表
*/
export function getVoteList(params: IVoteListReq) {
return http.Get<IResponse<IVoteListRes>>('/apis/api.vote.kunkunyu.com/v1alpha1/votes', {
params,
meta: { requestFrom: RequestFrom.Halo },
})
}
/**
* 投票详情
*/
export function getVoteDetail(name: string) {
return http.Get<IResponse<IVote>>(`/apis/api.vote.kunkunyu.com/v1alpha1/votes/${name}/detail`, {
meta: { requestFrom: RequestFrom.Halo },
})
}
/**
* 投票用户列表
*/
export function getVoteUserList(name: string) {
return http.Get<IResponse<unknown[]>>(`/apis/api.vote.kunkunyu.com/v1alpha1/votes/${name}/user-list`, {
meta: { requestFrom: RequestFrom.Halo },
})
}
/**
* 提交投票
* @param canAnonymously 是否允许匿名;非匿名时带个人 token
*/
export function submitVote(name: string, data: IVoteSubmitReq, canAnonymously = true) {
const headers: Record<string, string> = {}
if (!canAnonymously) {
const token = getPersonalToken()
if (token)
headers.Authorization = `Bearer ${token}`
}
return http.Post<IResponse<unknown>>(`/apis/api.vote.kunkunyu.com/v1alpha1/votes/${name}/submit`, data, {
headers,
meta: { requestFrom: RequestFrom.Halo },
})
}
/* ==================== 豆瓣(api.douban.moony.la) ==================== */
/**
* 获取豆瓣条目详情
*/
export function getDoubanDetail(url: string) {
return http.Get<IResponse<IDoubanDetail>>('/apis/api.douban.moony.la/v1alpha1/doubanmovies/-/getDoubanDetail', {
params: { url },
meta: { requestFrom: RequestFrom.Halo },
})
}
/* ==================== 评论验证码(api.commentwidget.halo.run) ==================== */
/**
* 获取评论验证码
*/
export function getCommentWidgetCaptcha() {
return http.Get<IResponse<string>>('/apis/api.commentwidget.halo.run/v1alpha1/captcha/-/generate', {
meta: { requestFrom: RequestFrom.Halo },
})
}
/* ==================== 数据看板(api.data.statistics.xhhao.com) ==================== */
/** 图表统计数据 */
export interface IDataStatistics {
tags: { name: string, count: number }[]
categories: { name: string, total: number }[]
articles: { date: string, count: number }[]
comments: { username: string, count: number }[]
top10Articles: { name: string, views: number }[]
[key: string]: unknown
}
/**
* 获取图表统计数据
* @description 标签、分类、文章发布趋势、评论活跃用户、热门文章 top10
*/
export function getChartData() {
return http.Get<IResponse<IDataStatistics>>('/apis/api.data.statistics.xhhao.com/v1alpha1/chart/data', {
meta: { requestFrom: RequestFrom.Halo },
})
}
/**
* 获取 Github 配置信息
*/
export function getGithubConfig() {
return http.Get<IResponse<unknown>>('/apis/api.data.statistics.xhhao.com/v1alpha1/github/config', {
meta: { requestFrom: RequestFrom.Halo },
})
}
/**
* 获取 Uptime Kuma 状态页面数据
*/
export function getUptimeKumaStatus() {
return http.Get<IResponse<unknown>>('/apis/api.data.statistics.xhhao.com/v1alpha1/uptime/status', {
meta: { requestFrom: RequestFrom.Halo },
})
}
/* ==================== 内部辅助 ==================== */
/**
* 工具类插件授权头(源自应用配置 pluginConfig.toolsPlugin.Authorization)
*/
function getToolsAuthorization(): string {
return getAppConfigFromStore().pluginConfig?.toolsPlugin?.Authorization || ''
}
/**
* 友链提交插件授权头(源自应用配置 pluginConfig.linksSubmitPlugin.Authorization)
*/
function getLinksSubmitAuthorization(): string {
return getAppConfigFromStore().pluginConfig?.linksSubmitPlugin?.Authorization || ''
}
/**
* 读取应用配置(store 未就绪时兜底为空)
* 注:待 src/store/appConfig.ts 建立后改为 useAppConfigStore 读取
*/
function getAppConfigFromStore(): IAppConfig {
// TODO: 迁移 store 后改为从 Pinia 读取,避免每次从 storage 解析
const cached = getCache<IAppConfig>('APP_GLOBAL_CONFIGS')
return cached || {}
}
/** 评论验证码 cookie key(供拦截器/页面使用) */
export { COMMENT_WIDGET_CAPTCHA_COOKIES }
export type { ILoveDailyItem, ILoveStory }