mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-05-06 20:42:57 +08:00
✨ Feature(custom): add log for cloud delete
This commit is contained in:
@@ -15,10 +15,8 @@ interface IConfigMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default class AlistApi {
|
export default class AlistApi {
|
||||||
static async delete(configMap: IConfigMap): Promise<boolean> {
|
static async delete({ fileName, config: { version, url, uploadPath, token } }: IConfigMap): Promise<boolean> {
|
||||||
const { fileName, config } = configMap
|
|
||||||
try {
|
try {
|
||||||
const { version, url, uploadPath, token } = config
|
|
||||||
if (String(version) === '2') {
|
if (String(version) === '2') {
|
||||||
deleteLog(fileName, 'Alist', false, 'Alist version 2 is not supported, deletion is skipped')
|
deleteLog(fileName, 'Alist', false, 'Alist version 2 is not supported, deletion is skipped')
|
||||||
return true
|
return true
|
||||||
@@ -35,12 +33,9 @@ export default class AlistApi {
|
|||||||
names: [path.basename(fileName)]
|
names: [path.basename(fileName)]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (result.data.code === 200) {
|
const ok = result.data.code === 200
|
||||||
deleteLog(fileName, 'Alist')
|
deleteLog(fileName, 'Alist', ok)
|
||||||
return true
|
return ok
|
||||||
}
|
|
||||||
deleteLog(fileName, 'Alist', false)
|
|
||||||
return false
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
deleteFailedLog(fileName, 'Alist', error)
|
deleteFailedLog(fileName, 'Alist', error)
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -50,12 +50,9 @@ export default class AListplistApi {
|
|||||||
names: [path.basename(fileName)]
|
names: [path.basename(fileName)]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (result.data.code === 200) {
|
const ok = result.data.code === 200
|
||||||
deleteLog(fileName, 'Alist')
|
deleteLog(fileName, 'Alist', ok)
|
||||||
return true
|
return ok
|
||||||
}
|
|
||||||
deleteLog(fileName, 'Alist', false)
|
|
||||||
return false
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
deleteFailedLog(fileName, 'Alist', error)
|
deleteFailedLog(fileName, 'Alist', error)
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -19,12 +19,9 @@ export default class AliyunApi {
|
|||||||
const client = new OSS({ ...config, region: config.area })
|
const client = new OSS({ ...config, region: config.area })
|
||||||
const key = AliyunApi.#getKey(fileName, config.path)
|
const key = AliyunApi.#getKey(fileName, config.path)
|
||||||
const result = await client.delete(key)
|
const result = await client.delete(key)
|
||||||
if (result.res.status === 204) {
|
const ok = result.res.status === 204
|
||||||
deleteLog(fileName, 'Aliyun')
|
deleteLog(fileName, 'Aliyun', ok)
|
||||||
return true
|
return ok
|
||||||
}
|
|
||||||
deleteLog(fileName, 'Aliyun', false)
|
|
||||||
return false
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
deleteFailedLog(fileName, 'Aliyun', error)
|
deleteFailedLog(fileName, 'Aliyun', error)
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -39,12 +39,9 @@ export default class GithubApi {
|
|||||||
sha: hash,
|
sha: hash,
|
||||||
branch
|
branch
|
||||||
})
|
})
|
||||||
if (status === 200) {
|
const ok = status === 200
|
||||||
deleteLog(fileName, 'GitHub')
|
deleteLog(fileName, 'GitHub', ok)
|
||||||
return true
|
return ok
|
||||||
}
|
|
||||||
deleteLog(fileName, 'GitHub', false)
|
|
||||||
return false
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
deleteFailedLog(fileName, 'GitHub', error)
|
deleteFailedLog(fileName, 'GitHub', error)
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -30,12 +30,9 @@ export default class ImgurApi {
|
|||||||
headers: { Authorization },
|
headers: { Authorization },
|
||||||
timeout: 30000
|
timeout: 30000
|
||||||
})
|
})
|
||||||
if (response.status === 200) {
|
const ok = response.status === 200
|
||||||
deleteLog(hash, 'Imgur')
|
deleteLog(hash, 'Imgur', ok)
|
||||||
return true
|
return ok
|
||||||
}
|
|
||||||
deleteLog(hash, 'Imgur', false)
|
|
||||||
return false
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
deleteFailedLog(hash, 'Imgur', error)
|
deleteFailedLog(hash, 'Imgur', error)
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -33,12 +33,9 @@ export default class LskyplistApi {
|
|||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
httpsAgent: requestAgent
|
httpsAgent: requestAgent
|
||||||
})
|
})
|
||||||
if (response.status === 200 && response.data.status === true) {
|
const ok = response.status === 200 && response.data.status === true
|
||||||
deleteLog(hash, 'Lskyplist')
|
deleteLog(hash, 'Lskyplist', ok)
|
||||||
return true
|
return ok
|
||||||
}
|
|
||||||
deleteLog(hash, 'Lskyplist', false)
|
|
||||||
return false
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
deleteFailedLog(hash, 'Lskyplist', error)
|
deleteFailedLog(hash, 'Lskyplist', error)
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -20,12 +20,9 @@ export default class PiclistApi {
|
|||||||
const response: AxiosResponse = await axios.post(url, {
|
const response: AxiosResponse = await axios.post(url, {
|
||||||
list: [fullResult]
|
list: [fullResult]
|
||||||
})
|
})
|
||||||
if (response.status === 200 && response.data?.success) {
|
const ok = response.status === 200 && response.data?.success
|
||||||
deleteLog(fullResult, 'Piclist')
|
deleteLog(fullResult, 'Piclist', ok)
|
||||||
return true
|
return ok
|
||||||
}
|
|
||||||
deleteLog(fullResult, 'Piclist', false)
|
|
||||||
return false
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
deleteFailedLog(fullResult, 'Piclist', error)
|
deleteFailedLog(fullResult, 'Piclist', error)
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -31,12 +31,9 @@ export default class QiniuApi {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
})) as any
|
})) as any
|
||||||
if (res?.respInfo?.statusCode === 200) {
|
const ok = res?.respInfo?.statusCode === 200
|
||||||
deleteLog(fileName, 'Qiniu')
|
deleteLog(fileName, 'Qiniu', ok)
|
||||||
return true
|
return ok
|
||||||
}
|
|
||||||
deleteLog(fileName, 'Qiniu', false)
|
|
||||||
return false
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
deleteFailedLog(fileName, 'Qiniu', error)
|
deleteFailedLog(fileName, 'Qiniu', error)
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -31,12 +31,9 @@ export default class SmmsApi {
|
|||||||
},
|
},
|
||||||
timeout: 30000
|
timeout: 30000
|
||||||
})
|
})
|
||||||
if (response.status === 200) {
|
const ok = response.status === 200
|
||||||
deleteLog(hash, 'Smms')
|
deleteLog(hash, 'Smms', ok)
|
||||||
return true
|
return ok
|
||||||
}
|
|
||||||
deleteLog(hash, 'Smms', false)
|
|
||||||
return false
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
deleteFailedLog(hash, 'Smms', error)
|
deleteFailedLog(hash, 'Smms', error)
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -32,12 +32,9 @@ export default class TcyunApi {
|
|||||||
Region: area,
|
Region: area,
|
||||||
Key: key
|
Key: key
|
||||||
})
|
})
|
||||||
if (result.statusCode === 204) {
|
const ok = result.statusCode === 204
|
||||||
deleteLog(fileName, 'Tcyun')
|
deleteLog(fileName, 'Tcyun', ok)
|
||||||
return true
|
return ok
|
||||||
}
|
|
||||||
deleteLog(fileName, 'Tcyun', false)
|
|
||||||
return false
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
deleteFailedLog(fileName, 'Tcyun', error)
|
deleteFailedLog(fileName, 'Tcyun', error)
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -24,12 +24,8 @@ export default class UpyunApi {
|
|||||||
key = `${path.replace(/^\/+|\/+$/, '')}/${fileName}`
|
key = `${path.replace(/^\/+|\/+$/, '')}/${fileName}`
|
||||||
}
|
}
|
||||||
const result = await client.deleteFile(key)
|
const result = await client.deleteFile(key)
|
||||||
if (result) {
|
deleteLog(fileName, 'Upyun', !!result)
|
||||||
deleteLog(fileName, 'Upyun')
|
return !!result
|
||||||
return true
|
|
||||||
}
|
|
||||||
deleteLog(fileName, 'Upyun', false)
|
|
||||||
return false
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
deleteFailedLog(fileName, 'Upyun', error)
|
deleteFailedLog(fileName, 'Upyun', error)
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -89,144 +89,134 @@ async function getDogeToken(accessKey: string, secretKey: string): Promise<IObj
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function removeFileFromS3InMain(configMap: IStringKeyMap, dogeMode: boolean = false) {
|
export async function removeFileFromS3InMain(configMap: IStringKeyMap, dogeMode: boolean = false) {
|
||||||
try {
|
const {
|
||||||
const {
|
url: rawUrl,
|
||||||
url: rawUrl,
|
type,
|
||||||
type,
|
config: {
|
||||||
config: {
|
accessKeyID,
|
||||||
accessKeyID,
|
secretAccessKey,
|
||||||
secretAccessKey,
|
bucketName,
|
||||||
bucketName,
|
endpoint,
|
||||||
endpoint,
|
pathStyleAccess,
|
||||||
pathStyleAccess,
|
rejectUnauthorized,
|
||||||
rejectUnauthorized,
|
proxy,
|
||||||
proxy,
|
urlPrefix
|
||||||
urlPrefix
|
|
||||||
}
|
|
||||||
} = configMap
|
|
||||||
let {
|
|
||||||
imgUrl,
|
|
||||||
config: { region }
|
|
||||||
} = configMap
|
|
||||||
if (type === 'aws-s3' || type === 'aws-s3-plist') {
|
|
||||||
imgUrl = rawUrl || imgUrl || ''
|
|
||||||
}
|
}
|
||||||
let fileKey
|
} = configMap
|
||||||
if (urlPrefix && imgUrl.startsWith(urlPrefix)) {
|
let {
|
||||||
const urlPrefixObj = new URL(urlPrefix)
|
imgUrl,
|
||||||
const imgUrlObj = new URL(imgUrl)
|
config: { region }
|
||||||
if (imgUrlObj.pathname.startsWith(urlPrefixObj.pathname)) {
|
} = configMap
|
||||||
fileKey = imgUrlObj.pathname.substring(urlPrefixObj.pathname.length).replace(/^\/+/, '')
|
if (type === 'aws-s3' || type === 'aws-s3-plist') {
|
||||||
} else {
|
imgUrl = rawUrl || imgUrl || ''
|
||||||
fileKey = imgUrlObj.pathname.replace(/^\/+/, '')
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const url = new URL(!/^https?:\/\//.test(imgUrl) ? `http://${imgUrl}` : imgUrl)
|
|
||||||
fileKey = url.pathname.replace(/^\/+/, '')
|
|
||||||
if (pathStyleAccess) {
|
|
||||||
fileKey = fileKey.replace(/^[^/]+\//, '')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const endpointUrl: string | undefined = endpoint
|
|
||||||
? /^https?:\/\//.test(endpoint)
|
|
||||||
? endpoint
|
|
||||||
: `http://${endpoint}`
|
|
||||||
: undefined
|
|
||||||
if (endpointUrl && endpointUrl.includes('cloudflarestorage')) {
|
|
||||||
region = region || 'auto'
|
|
||||||
}
|
|
||||||
const sslEnabled = endpointUrl ? endpointUrl.startsWith('https') : true
|
|
||||||
const agent = getAgent(proxy, sslEnabled)
|
|
||||||
const commonOptions: AgentOptions = {
|
|
||||||
keepAlive: true,
|
|
||||||
keepAliveMsecs: 1000,
|
|
||||||
scheduling: 'lifo' as 'lifo' | 'fifo' | undefined
|
|
||||||
}
|
|
||||||
const extraOptions = sslEnabled ? { rejectUnauthorized: !!rejectUnauthorized } : {}
|
|
||||||
const handler = sslEnabled
|
|
||||||
? new NodeHttpHandler({
|
|
||||||
httpsAgent: agent.https
|
|
||||||
? agent.https
|
|
||||||
: new https.Agent({
|
|
||||||
...commonOptions,
|
|
||||||
...extraOptions
|
|
||||||
})
|
|
||||||
})
|
|
||||||
: new NodeHttpHandler({
|
|
||||||
httpAgent: agent.http
|
|
||||||
? agent.http
|
|
||||||
: new http.Agent({
|
|
||||||
...commonOptions,
|
|
||||||
...extraOptions
|
|
||||||
})
|
|
||||||
})
|
|
||||||
const s3Options: S3ClientConfig = {
|
|
||||||
credentials: {
|
|
||||||
accessKeyId: accessKeyID,
|
|
||||||
secretAccessKey
|
|
||||||
},
|
|
||||||
endpoint: endpointUrl,
|
|
||||||
tls: sslEnabled,
|
|
||||||
forcePathStyle: pathStyleAccess,
|
|
||||||
region,
|
|
||||||
requestHandler: handler
|
|
||||||
}
|
|
||||||
if (dogeMode) {
|
|
||||||
s3Options.credentials = {
|
|
||||||
accessKeyId: configMap.config.accessKeyID,
|
|
||||||
secretAccessKey: configMap.config.secretAccessKey,
|
|
||||||
sessionToken: configMap.config.sessionToken
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let result: any
|
|
||||||
try {
|
|
||||||
fileKey = decodeURIComponent(fileKey)
|
|
||||||
} catch (err: any) {}
|
|
||||||
try {
|
|
||||||
const client = new S3Client(s3Options)
|
|
||||||
const command = new DeleteObjectCommand({
|
|
||||||
Bucket: bucketName,
|
|
||||||
Key: fileKey
|
|
||||||
})
|
|
||||||
result = await client.send(command)
|
|
||||||
} catch (err: any) {
|
|
||||||
s3Options.region = 'us-east-1'
|
|
||||||
const client = new S3Client(s3Options)
|
|
||||||
const command = new DeleteObjectCommand({
|
|
||||||
Bucket: bucketName,
|
|
||||||
Key: fileKey
|
|
||||||
})
|
|
||||||
result = await client.send(command)
|
|
||||||
}
|
|
||||||
return result.$metadata.httpStatusCode === 204
|
|
||||||
} catch (err: any) {
|
|
||||||
logger.error(err)
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
let fileKey
|
||||||
|
if (urlPrefix && imgUrl.startsWith(urlPrefix)) {
|
||||||
|
const urlPrefixObj = new URL(urlPrefix)
|
||||||
|
const imgUrlObj = new URL(imgUrl)
|
||||||
|
if (imgUrlObj.pathname.startsWith(urlPrefixObj.pathname)) {
|
||||||
|
fileKey = imgUrlObj.pathname.substring(urlPrefixObj.pathname.length).replace(/^\/+/, '')
|
||||||
|
} else {
|
||||||
|
fileKey = imgUrlObj.pathname.replace(/^\/+/, '')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const url = new URL(!/^https?:\/\//.test(imgUrl) ? `http://${imgUrl}` : imgUrl)
|
||||||
|
fileKey = url.pathname.replace(/^\/+/, '')
|
||||||
|
if (pathStyleAccess) {
|
||||||
|
fileKey = fileKey.replace(/^[^/]+\//, '')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const endpointUrl: string | undefined = endpoint
|
||||||
|
? /^https?:\/\//.test(endpoint)
|
||||||
|
? endpoint
|
||||||
|
: `http://${endpoint}`
|
||||||
|
: undefined
|
||||||
|
if (endpointUrl && endpointUrl.includes('cloudflarestorage')) {
|
||||||
|
region = region || 'auto'
|
||||||
|
}
|
||||||
|
const sslEnabled = endpointUrl ? endpointUrl.startsWith('https') : true
|
||||||
|
const agent = getAgent(proxy, sslEnabled)
|
||||||
|
const commonOptions: AgentOptions = {
|
||||||
|
keepAlive: true,
|
||||||
|
keepAliveMsecs: 1000,
|
||||||
|
scheduling: 'lifo' as 'lifo' | 'fifo' | undefined
|
||||||
|
}
|
||||||
|
const extraOptions = sslEnabled ? { rejectUnauthorized: !!rejectUnauthorized } : {}
|
||||||
|
const handler = sslEnabled
|
||||||
|
? new NodeHttpHandler({
|
||||||
|
httpsAgent: agent.https
|
||||||
|
? agent.https
|
||||||
|
: new https.Agent({
|
||||||
|
...commonOptions,
|
||||||
|
...extraOptions
|
||||||
|
})
|
||||||
|
})
|
||||||
|
: new NodeHttpHandler({
|
||||||
|
httpAgent: agent.http
|
||||||
|
? agent.http
|
||||||
|
: new http.Agent({
|
||||||
|
...commonOptions,
|
||||||
|
...extraOptions
|
||||||
|
})
|
||||||
|
})
|
||||||
|
const s3Options: S3ClientConfig = {
|
||||||
|
credentials: {
|
||||||
|
accessKeyId: accessKeyID,
|
||||||
|
secretAccessKey
|
||||||
|
},
|
||||||
|
endpoint: endpointUrl,
|
||||||
|
tls: sslEnabled,
|
||||||
|
forcePathStyle: pathStyleAccess,
|
||||||
|
region,
|
||||||
|
requestHandler: handler
|
||||||
|
}
|
||||||
|
if (dogeMode) {
|
||||||
|
s3Options.credentials = {
|
||||||
|
accessKeyId: configMap.config.accessKeyID,
|
||||||
|
secretAccessKey: configMap.config.secretAccessKey,
|
||||||
|
sessionToken: configMap.config.sessionToken
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let result: any
|
||||||
|
try {
|
||||||
|
fileKey = decodeURIComponent(fileKey)
|
||||||
|
} catch (err: any) {}
|
||||||
|
try {
|
||||||
|
const client = new S3Client(s3Options)
|
||||||
|
const command = new DeleteObjectCommand({
|
||||||
|
Bucket: bucketName,
|
||||||
|
Key: fileKey
|
||||||
|
})
|
||||||
|
result = await client.send(command)
|
||||||
|
} catch (err: any) {
|
||||||
|
s3Options.region = 'us-east-1'
|
||||||
|
const client = new S3Client(s3Options)
|
||||||
|
const command = new DeleteObjectCommand({
|
||||||
|
Bucket: bucketName,
|
||||||
|
Key: fileKey
|
||||||
|
})
|
||||||
|
result = await client.send(command)
|
||||||
|
}
|
||||||
|
return result.$metadata.httpStatusCode === 204
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function removeFileFromDogeInMain(configMap: IStringKeyMap) {
|
export async function removeFileFromDogeInMain(configMap: IStringKeyMap) {
|
||||||
try {
|
const {
|
||||||
const {
|
config: { bucketName, AccessKey, SecretKey }
|
||||||
config: { bucketName, AccessKey, SecretKey }
|
} = configMap
|
||||||
} = configMap
|
const token = (await getDogeToken(AccessKey, SecretKey)) as DogecloudTokenFull
|
||||||
const token = (await getDogeToken(AccessKey, SecretKey)) as DogecloudTokenFull
|
const bucket = token.Buckets?.find(item => item.name === bucketName || item.s3Bucket === bucketName)
|
||||||
const bucket = token.Buckets?.find(item => item.name === bucketName || item.s3Bucket === bucketName)
|
const newConfigMap = { ...configMap }
|
||||||
const newConfigMap = { ...configMap }
|
newConfigMap.config = {
|
||||||
newConfigMap.config = {
|
...newConfigMap.config,
|
||||||
...newConfigMap.config,
|
accessKeyID: token.Credentials?.accessKeyId,
|
||||||
accessKeyID: token.Credentials?.accessKeyId,
|
secretAccessKey: token.Credentials?.secretAccessKey,
|
||||||
secretAccessKey: token.Credentials?.secretAccessKey,
|
sessionToken: token.Credentials?.sessionToken,
|
||||||
sessionToken: token.Credentials?.sessionToken,
|
endpoint: bucket?.s3Endpoint,
|
||||||
endpoint: bucket?.s3Endpoint,
|
region: dogeRegionMap[bucket?.s3Endpoint?.split('.')[1] || 'ap-shanghai'],
|
||||||
region: dogeRegionMap[bucket?.s3Endpoint?.split('.')[1] || 'ap-shanghai'],
|
bucketName: bucket?.s3Bucket
|
||||||
bucketName: bucket?.s3Bucket
|
|
||||||
}
|
|
||||||
return await removeFileFromS3InMain(newConfigMap, true)
|
|
||||||
} catch (err: any) {
|
|
||||||
logger.error(err)
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
return await removeFileFromS3InMain(newConfigMap, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
function createHuaweiAuthorization(
|
function createHuaweiAuthorization(
|
||||||
@@ -250,35 +240,25 @@ export async function removeFileFromHuaweiInMain(configMap: IStringKeyMap) {
|
|||||||
path = path === '/' ? '' : path
|
path = path === '/' ? '' : path
|
||||||
const date = new Date().toUTCString()
|
const date = new Date().toUTCString()
|
||||||
const authorization = createHuaweiAuthorization(bucketName, path, fileName, accessKeyId, accessKeySecret, date)
|
const authorization = createHuaweiAuthorization(bucketName, path, fileName, accessKeyId, accessKeySecret, date)
|
||||||
try {
|
const res = await axios.request({
|
||||||
const res = await axios.request({
|
url: `https://${bucketName}.${endpoint}${encodeURI(path)}/${encodeURIComponent(fileName)}`,
|
||||||
url: `https://${bucketName}.${endpoint}${encodeURI(path)}/${encodeURIComponent(fileName)}`,
|
method: 'DELETE',
|
||||||
method: 'DELETE',
|
responseType: 'json',
|
||||||
responseType: 'json',
|
headers: {
|
||||||
headers: {
|
Host: `${bucketName}.${endpoint}`,
|
||||||
Host: `${bucketName}.${endpoint}`,
|
Date: date,
|
||||||
Date: date,
|
Authorization: authorization
|
||||||
Authorization: authorization
|
}
|
||||||
}
|
})
|
||||||
})
|
return res.status === 204
|
||||||
return res.status === 204
|
|
||||||
} catch (error: any) {
|
|
||||||
logger.error(error)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function removeFileFromSFTPInMain(config: ISftpPlistConfig, fileName: string) {
|
export async function removeFileFromSFTPInMain(config: ISftpPlistConfig, fileName: string) {
|
||||||
try {
|
const client = SSHClient.instance
|
||||||
const client = SSHClient.instance
|
await client.connect(config)
|
||||||
await client.connect(config)
|
const uploadPath = `/${config.uploadPath || ''}/`.replace(/\/+/g, '/')
|
||||||
const uploadPath = `/${config.uploadPath || ''}/`.replace(/\/+/g, '/')
|
const remote = path.join(uploadPath, fileName)
|
||||||
const remote = path.join(uploadPath, fileName)
|
const deleteResult = await client.deleteFileSFTP(config, remote)
|
||||||
const deleteResult = await client.deleteFileSFTP(config, remote)
|
client.close()
|
||||||
client.close()
|
return deleteResult
|
||||||
return deleteResult
|
|
||||||
} catch (err: any) {
|
|
||||||
logger.error(err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
|
import logger from '@core/picgo/logger'
|
||||||
|
|
||||||
export const deleteLog = (fileName?: string, type?: string, isSuccess = true, msg?: string) => {
|
export const deleteLog = (fileName?: string, type?: string, isSuccess = true, msg?: string) => {
|
||||||
console.log(`Delete ${fileName} on ${type} ${isSuccess ? 'success' : 'failed'}, message: ${msg || ''}`)
|
logger.info(`Delete ${fileName} on ${type} ${isSuccess ? 'successfully' : 'failed'} ${msg ? 'msg: ' + msg : ''}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const deleteFailedLog = (fileName: string, type: string, error: any) => {
|
export const deleteFailedLog = (fileName: string, type: string, error: any) => {
|
||||||
deleteLog(fileName, type, false)
|
deleteLog(fileName, type, false)
|
||||||
console.error(error)
|
logger.error(error)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user