🚧 WIP(custom): v3.0.0 migrate to vite and esm

This commit is contained in:
Kuingsmile
2025-07-31 17:37:30 +08:00
parent cd76bc7c10
commit 054f4b4cff
597 changed files with 197292 additions and 13329 deletions

View File

@@ -1,16 +1,17 @@
import path from 'node:path'
import db from '@core/datastore'
import logger from '@core/picgo/logger'
import { Octokit } from '@octokit/rest'
import axios from 'axios'
import { app } from 'electron'
import fs from 'fs-extra'
import { HttpsProxyAgent } from 'hpagent'
import path from 'path'
import { Octokit } from '@octokit/rest'
import { createClient, AuthType, WebDAVClientOptions } from 'webdav'
import { AuthType, createClient, WebDAVClientOptions } from 'webdav'
import db from '@core/datastore'
import logger from '@core/picgo/logger'
import { configPaths } from '#/utils/configPaths'
import { ISyncConfig } from '#/types/types'
import { formatEndpoint } from '#/utils/common'
import { configPaths } from '#/utils/configPaths'
const STORE_PATH = app.getPath('userData')
@@ -36,16 +37,16 @@ const getSyncConfig = () => {
const getProxyagent = (proxy: string | undefined) => {
return proxy
? new HttpsProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
rejectUnauthorized: false,
proxy: proxy.replace('127.0.0.1', 'localhost'),
scheduling: 'lifo'
})
keepAlive: true,
keepAliveMsecs: 1000,
rejectUnauthorized: false,
proxy: proxy.replace('127.0.0.1', 'localhost'),
scheduling: 'lifo'
})
: undefined
}
function getOctokit(syncConfig: ISyncConfig) {
function getOctokit (syncConfig: ISyncConfig) {
const { token, proxy } = syncConfig
return new Octokit({
auth: token,
@@ -82,7 +83,7 @@ const isSyncConfigValidate = ({
return type && username && repo && branch && token
}
async function uploadLocalToRemote(syncConfig: ISyncConfig, fileName: string) {
async function uploadLocalToRemote (syncConfig: ISyncConfig, fileName: string) {
const localFilePath = path.join(STORE_PATH, fileName)
if (!fs.existsSync(localFilePath)) {
return false
@@ -160,7 +161,7 @@ async function uploadLocalToRemote(syncConfig: ISyncConfig, fileName: string) {
}
}
async function updateLocalToRemote(syncConfig: ISyncConfig, fileName: string) {
async function updateLocalToRemote (syncConfig: ISyncConfig, fileName: string) {
const localFilePath = path.join(STORE_PATH, fileName)
if (!fs.existsSync(localFilePath)) {
return false
@@ -276,7 +277,7 @@ async function updateLocalToRemote(syncConfig: ISyncConfig, fileName: string) {
}
}
async function uploadFile(fileName: string[]): Promise<number> {
async function uploadFile (fileName: string[]): Promise<number> {
const syncConfig = getSyncConfig()
if (!isSyncConfigValidate(syncConfig)) {
logger.error('sync config is invalid')
@@ -301,7 +302,7 @@ async function uploadFile(fileName: string[]): Promise<number> {
return count
}
async function downloadAndWriteFile(url: string, localFilePath: string, config: any, isWriteJson = false) {
async function downloadAndWriteFile (url: string, localFilePath: string, config: any, isWriteJson = false) {
const res = await axios.get(url, config)
if (isHttpResSuccess(res)) {
await fs.writeFile(
@@ -313,7 +314,7 @@ async function downloadAndWriteFile(url: string, localFilePath: string, config:
return false
}
async function downloadRemoteToLocal(syncConfig: ISyncConfig, fileName: string) {
async function downloadRemoteToLocal (syncConfig: ISyncConfig, fileName: string) {
const localFilePath = path.join(STORE_PATH, fileName)
const { username, repo, branch, token, proxy, type } = syncConfig
try {
@@ -393,7 +394,7 @@ async function downloadRemoteToLocal(syncConfig: ISyncConfig, fileName: string)
}
}
async function downloadFile(fileName: string[]): Promise<number> {
async function downloadFile (fileName: string[]): Promise<number> {
const syncConfig = getSyncConfig()
if (!isSyncConfigValidate(syncConfig)) {
logger.error('sync config is invalid')
@@ -409,4 +410,4 @@ async function downloadFile(fileName: string[]): Promise<number> {
return (await Promise.all(fileName.map(downloadFunc))).reduce((a, b) => a + b, 0)
}
export { uploadFile, downloadFile }
export { downloadFile, uploadFile }