mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-07-10 23:13:20 +08:00
fix 默认下载路径
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "moviepilot",
|
"name": "moviepilot",
|
||||||
"version": "1.9.2",
|
"version": "1.9.2-1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"bin": "dist/service.js",
|
"bin": "dist/service.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -718,12 +718,6 @@ export interface NotificationSwitch {
|
|||||||
vocechat: boolean
|
vocechat: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
// 环境设置
|
|
||||||
export interface Setting {
|
|
||||||
// 下载目录
|
|
||||||
DOWNLOAD_PATH: string
|
|
||||||
}
|
|
||||||
|
|
||||||
// 文件浏览接口
|
// 文件浏览接口
|
||||||
export interface EndPoints {
|
export interface EndPoints {
|
||||||
// 文件列表
|
// 文件列表
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
|
import { MediaDirectory } from '@/api/types'
|
||||||
import FileBrowser from '@/components/FileBrowser.vue'
|
import FileBrowser from '@/components/FileBrowser.vue'
|
||||||
|
|
||||||
const endpoints = {
|
const endpoints = {
|
||||||
@@ -29,42 +30,53 @@ const endpoints = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// 读取下载目录
|
// 当前目录
|
||||||
const path: Ref<string | undefined> = ref()
|
const path: Ref<string | undefined> = ref()
|
||||||
|
|
||||||
// 调用API,加载当前系统环境设置
|
// 下载目录列表
|
||||||
function loadSystemSettings(): Promise<string> {
|
const downloadDirectories = ref<MediaDirectory[]>([])
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
api
|
|
||||||
.get('system/env')
|
|
||||||
.then((result: any) => {
|
|
||||||
let path = '/'
|
|
||||||
if (result.success)
|
|
||||||
path = result.data?.DOWNLOAD_PATH || '/'
|
|
||||||
|
|
||||||
if (!path.endsWith('/'))
|
// 计算公共路径
|
||||||
path += '/'
|
function findCommonPath(paths: string[]): string {
|
||||||
|
if (!paths || paths.length === 0) return ''
|
||||||
resolve(path)
|
if (paths.length === 1) return paths[0]
|
||||||
})
|
const normalizedPaths = paths.map(path => path.replace(/\\/g, '/'))
|
||||||
.catch(error => reject(error))
|
const splitPaths = normalizedPaths.map(path => path.split('/'))
|
||||||
})
|
let commonParts: string[] = []
|
||||||
|
for (let i = 0; i < splitPaths[0].length; i++) {
|
||||||
|
const part = splitPaths[0][i]
|
||||||
|
if (splitPaths.every(pathParts => pathParts[i] === part)) {
|
||||||
|
commonParts.push(part)
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let commonPath = commonParts.join('/')
|
||||||
|
if (commonPath.includes(':')) {
|
||||||
|
commonPath = commonPath.replace('/', '\\')
|
||||||
|
}
|
||||||
|
return commonPath.length > 0 ? commonPath : paths[0][0] === '/' ? '/' : ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 查询下载目录
|
||||||
|
async function loadDownloadDirectories() {
|
||||||
|
try {
|
||||||
|
const result: { [key: string]: any } = await api.get('system/setting/DownloadDirectories')
|
||||||
|
if (result.success && result.data?.value) {
|
||||||
|
downloadDirectories.value = result.data.value
|
||||||
|
path.value = findCommonPath(downloadDirectories.value.map(item => item.path) as string[])
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 目录变化
|
||||||
function pathChanged(_path: string) {
|
function pathChanged(_path: string) {
|
||||||
path.value = _path
|
path.value = _path
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onBeforeMount(loadDownloadDirectories)
|
||||||
loadSystemSettings()
|
|
||||||
.then((res) => {
|
|
||||||
path.value = res
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error(error)
|
|
||||||
path.value = '/'
|
|
||||||
})
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
Reference in New Issue
Block a user