Skip to content

Commit

Permalink
Merge branch 'v3' into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/components.d.ts
  • Loading branch information
XPoet committed Feb 20, 2024
2 parents 19a093e + 269400b commit c05dc36
Show file tree
Hide file tree
Showing 125 changed files with 3,767 additions and 3,158 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

# PicX

[![Author](https://img.shields.io/badge/author-XPoet-violet.svg)](https://github.com/XPoet)
[![Release](https://img.shields.io/github/release/XPoet/picx.svg)](https://github.com/XPoet/picx/releases)
[![License](https://img.shields.io/github/license/XPoet/picx.svg)](https://github.com/XPoet/picx/blob/master/LICENSE)
[![Stars](https://img.shields.io/github/stars/XPoet/picx)](https://github.com/XPoet/picx)
[![Issues](https://img.shields.io/github/issues/XPoet/picx)](https://github.com/XPoet/picx/issues)
[![Release](https://img.shields.io/github/release/XPoet/picx?style=flat&logo=github)](https://github.com/XPoet/picx/releases)
[![License](https://img.shields.io/github/license/XPoet/picx?style=flat&logo=github)](https://github.com/XPoet/picx/blob/master/LICENSE)
[![Stars](https://img.shields.io/github/stars/XPoet/picx?style=flat&logo=github&color=3366cc)](https://github.com/XPoet/picx)
[![Issues](https://img.shields.io/github/issues/XPoet/picx?style=flat&logo=github)](https://github.com/XPoet/picx/issues)
[![Deploy](https://github.com/XPoet/picx/workflows/deploy/badge.svg)](https://github.com/XPoet/picx/actions/workflows/deploy.yml)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-Airbnb-hotpink.svg)](https://github.com/lin-123/javascript)

**[PicX](https://picx.xpoet.cn)** 是一款基于 GitHub API 开发的图床工具,提供图片上传托管、生成图片链接和常用图片工具箱服务。

Expand All @@ -28,6 +26,10 @@

**在线使用入口 https://picx.xpoet.cn**

> **重要提示:**
> - 为进一步简化用户操作,PicX 自 `v3.0` 起,不再支持自由选择仓库和分支,统一使用内置的仓库和分支。
> - 如需继续使用自定义的仓库和分支,请使用 [PicX v2.0](https://v2.picx.xpoet.cn)
## 文档 | Documents

**官方文档 https://picx-docs.xpoet.cn**
Expand Down
10 changes: 0 additions & 10 deletions auto-imports.d.ts

This file was deleted.

65 changes: 0 additions & 65 deletions components.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "picx",
"version": "2.5.0",
"version": "3.0.0",
"private": false,
"author": "XPoet <i@xpoet.cn>",
"license": "AGPL-3.0",
Expand Down
131 changes: 2 additions & 129 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,136 +1,9 @@
<template>
<el-config-provider :size="elementPlusSize" :z-index="3000" :locale="elementPlusLocale">
<main-container />
</el-config-provider>
<app-wrap />
</template>

<script setup lang="ts">
import { onMounted, ref, getCurrentInstance, watch, computed } from 'vue'
import { ElConfigProvider } from 'element-plus'
import zhCN from 'element-plus/lib/locale/lang/zh-cn'
import zhTW from 'element-plus/lib/locale/lang/zh-tw'
import en from 'element-plus/lib/locale/lang/en'
import setThemeMode from '@/utils/set-theme-mode'
import { useStore } from '@/stores'
import { getLanguageByRegion, getRegionByIP, setWindowTitle, throttle } from '@/utils'
import { ElementPlusSizeEnum, LanguageEnum } from '@/common/model'
import MainContainer from '@/views/main-container/main-container.vue'
import router from '@/router'
import { initGithubAuthorize } from '@/views/picx-login/picx-login.util'
const instance = getCurrentInstance()
const store = useStore()
const userSettings = computed(() => store.getters.getUserSettings).value
const elementPlusSize = ref<ElementPlusSizeEnum>(ElementPlusSizeEnum.default)
const elementPlusLocale = ref(zhCN) // zhCN | zhTW | en
const elementPlusSizeHandle = (width: number) => {
if (width <= 600) {
store?.dispatch('SET_USER_SETTINGS', {
elementPlusSize: ElementPlusSizeEnum.small
})
elementPlusSize.value = ElementPlusSizeEnum.small
} else if (width <= 900) {
store?.dispatch('SET_USER_SETTINGS', {
elementPlusSize: ElementPlusSizeEnum.default
})
elementPlusSize.value = ElementPlusSizeEnum.default
} else {
store?.dispatch('SET_USER_SETTINGS', {
elementPlusSize: ElementPlusSizeEnum.large
})
elementPlusSize.value = ElementPlusSizeEnum.large
}
}
const setLanguage = (language: LanguageEnum) => {
if (language === LanguageEnum.zhCN) {
elementPlusLocale.value = zhCN // 设置 Element Plus 组件库语言
instance!.proxy!.$i18n.locale = 'zh-CN' // 设置 i18n 语言
} else if (language === LanguageEnum.zhTW) {
elementPlusLocale.value = zhTW
instance!.proxy!.$i18n.locale = 'zh-TW'
} else if (language === LanguageEnum.en) {
elementPlusLocale.value = en
instance!.proxy!.$i18n.locale = 'en'
} else {
elementPlusLocale.value = zhCN
instance!.proxy!.$i18n.locale = 'zh-CN'
}
setWindowTitle(router.currentRoute.value.meta.title as string)
}
const setLanguageByIP = () => {
getRegionByIP().then((region) => {
const language = getLanguageByRegion(region)
if (language !== userSettings.language) {
const confirmTxt = instance?.proxy?.$t(`confirm`, language)
const msgTxt = instance?.proxy?.$t(`toggle_language_msg`, language, {
region: instance?.proxy?.$t(`region.${region}`, language),
language: instance?.proxy?.$t(`language.${language}`, language)
})
const msgInstance = ElMessage({
customClass: 'custom-message-container',
duration: 0,
offset: 20,
type: 'info',
message: `<div class="content-box language">
<span class="msg">${msgTxt}</span>
<spna class="btn-box">
<span class="confirm btn">${confirmTxt}</span>
</spna>
</div>`,
dangerouslyUseHTMLString: true,
showClose: true
})
document
.querySelector('.custom-message-container .language .confirm')
?.addEventListener('click', () => {
setLanguage(language)
store.dispatch('SET_USER_SETTINGS', {
language
})
msgInstance.close()
})
}
})
}
const initSetLanguage = () => {
// 初始化设置
setLanguage(userSettings.language)
// 根据 IP 自动设置
setLanguageByIP()
}
const init = () => {
elementPlusSizeHandle(window.innerWidth)
window.addEventListener(
'resize',
throttle((e: any) => {
elementPlusSizeHandle(e.target.innerWidth)
}, 600)
)
setThemeMode()
initSetLanguage()
initGithubAuthorize()
}
watch(
() => userSettings.language,
(language: LanguageEnum) => {
setLanguage(language)
}
)
onMounted(() => {
init()
})
import AppWrap from '@/views/app-wrap/app-wrap.vue'
</script>

<style lang="stylus">
Expand Down
18 changes: 7 additions & 11 deletions src/common/api/branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import i18n from '@/plugins/vue/i18n'
export const getBranchInfo = (owner: string, repo: string, branch: string) => {
return request({
url: `/repos/${owner}/${repo}/branches/${branch}`,
method: 'GET'
method: 'GET',
noCache: true
})
}

Expand All @@ -31,12 +32,7 @@ export const getBranchInfoList = (
const tmpList: any[] = await request({
url: `/repos/${owner}/${repo}/branches`,
method: 'GET',
cache: {
maxAge: 0 // 设置缓存的最大寿命为 0,禁用缓存
},
params: {
timestamp: Date.now() // 添加时间戳参数,防止获取缓存的数据
}
noCache: true
})

if (tmpList && tmpList.length) {
Expand All @@ -62,10 +58,10 @@ export const getBranchInfoList = (
* @param cb
*/
export const checkoutGhPagesBranch = async (userConfigInfo: UserConfigInfoModel, cb?: any) => {
const { owner, selectedRepo: repo, selectedBranch } = userConfigInfo
const { owner, repo, branch } = userConfigInfo

const initLoading = ElLoading.service({
text: i18n.global.t('settings.image_hosting_deploy.deploying')
text: i18n.global.t('settings_page.image_hosting_deploy.deploying')
})

const cbHandler = (evt: boolean = false) => {
Expand Down Expand Up @@ -98,7 +94,7 @@ export const checkoutGhPagesBranch = async (userConfigInfo: UserConfigInfoModel,
// 2、获取当前分支的 SHA 值
let sha = ''
const res1 = await request({
url: `/repos/${owner}/${repo}/git/refs/heads/${selectedBranch}`,
url: `/repos/${owner}/${repo}/git/refs/heads/${branch}`,
method: 'GET'
})

Expand All @@ -115,7 +111,7 @@ export const checkoutGhPagesBranch = async (userConfigInfo: UserConfigInfoModel,
const res2 = await request({
url: `/repos/${owner}/${repo}/git/refs`,
method: 'POST',
params: {
data: {
ref: `refs/heads/${GH_PAGES}`,
sha
}
Expand Down
21 changes: 12 additions & 9 deletions src/common/api/dir.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { store } from '@/stores'
import { getFileSuffix, isImage, createManagementImageObject, getUuid } from '@/utils'
import { getFileSuffix, isImage, createManagementImageObject } from '@/utils'
import request from '@/utils/request'
import { UserConfigInfoModel } from '@/common/model'

Expand All @@ -8,15 +8,19 @@ import { UserConfigInfoModel } from '@/common/model'
* @param userConfigInfo
* @param path 路径
*/
export const getDirInfoList = (userConfigInfo: UserConfigInfoModel, path: string = '') => {
const { owner, selectedRepo: repo, selectedBranch: ref } = userConfigInfo
export const getDirInfoList = (
userConfigInfo: UserConfigInfoModel,
path: string = ''
): Promise<[]> => {
const { owner, repo, branch } = userConfigInfo
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
const tmpList = await request({
url: `/repos/${owner}/${repo}/contents/${path}`,
method: 'GET',
noShowErrMsg: true,
params: {
ref
ref: branch
}
})

Expand All @@ -30,7 +34,7 @@ export const getDirInfoList = (userConfigInfo: UserConfigInfoModel, path: string
}))
)
} else {
resolve(null)
resolve([])
}
})
}
Expand All @@ -41,17 +45,16 @@ export const getDirInfoList = (userConfigInfo: UserConfigInfoModel, path: string
* @param path
*/
export const getRepoPathContent = (userConfigInfo: UserConfigInfoModel, path: string = '') => {
const { owner, selectedRepo: repo, selectedBranch: ref } = userConfigInfo
const { owner, repo, branch } = userConfigInfo

// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
const res = await request({
url: `/repos/${owner}/${repo}/contents/${path}`,
method: 'GET',
noCache: true,
params: {
// 防止浏览器缓存
'no-cache': getUuid(),
ref
ref: branch
}
})

Expand Down

0 comments on commit c05dc36

Please sign in to comment.