mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
optimize
This commit is contained in:
@@ -75,18 +75,13 @@ export class NTQQFileApi extends Service {
|
||||
// 上传文件到QQ的文件夹
|
||||
async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC, elementSubType = 0) {
|
||||
const fileMd5 = await calculateFileMD5(filePath)
|
||||
let ext = (await this.getFileType(filePath))?.ext || ''
|
||||
if (ext) {
|
||||
ext = '.' + ext
|
||||
let fileName = path.basename(filePath)
|
||||
if (!fileName.includes('.')) {
|
||||
const ext = (await this.getFileType(filePath))?.ext
|
||||
fileName += ext ? '.' + ext : ''
|
||||
}
|
||||
let fileName = `${path.basename(filePath)}`
|
||||
if (fileName.indexOf('.') === -1) {
|
||||
fileName += ext
|
||||
}
|
||||
const session = getSession()
|
||||
let mediaPath: string
|
||||
if (session) {
|
||||
mediaPath = session?.getMsgService().getRichMediaFilePathForGuild({
|
||||
const mediaPath = await invoke(NTMethod.MEDIA_FILE_PATH, [{
|
||||
path_info: {
|
||||
md5HexStr: fileMd5,
|
||||
fileName: fileName,
|
||||
elementType: elementType,
|
||||
@@ -94,22 +89,9 @@ export class NTQQFileApi extends Service {
|
||||
thumbSize: 0,
|
||||
needCreate: true,
|
||||
downloadType: 1,
|
||||
file_uuid: ''
|
||||
})
|
||||
} else {
|
||||
mediaPath = await invoke(NTMethod.MEDIA_FILE_PATH, [{
|
||||
path_info: {
|
||||
md5HexStr: fileMd5,
|
||||
fileName: fileName,
|
||||
elementType: elementType,
|
||||
elementSubType,
|
||||
thumbSize: 0,
|
||||
needCreate: true,
|
||||
downloadType: 1,
|
||||
file_uuid: '',
|
||||
},
|
||||
}])
|
||||
}
|
||||
file_uuid: '',
|
||||
},
|
||||
}])
|
||||
await copyFile(filePath, mediaPath)
|
||||
const fileSize = (await stat(filePath)).size
|
||||
return {
|
||||
@@ -117,7 +99,6 @@ export class NTQQFileApi extends Service {
|
||||
fileName,
|
||||
path: mediaPath,
|
||||
fileSize,
|
||||
ext
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +157,11 @@ export class NTQQFileApi extends Service {
|
||||
}
|
||||
|
||||
async getImageSize(filePath: string) {
|
||||
return await invoke<{ width: number; height: number }>(
|
||||
return await invoke<{
|
||||
width: number
|
||||
height: number
|
||||
type: string
|
||||
}>(
|
||||
NTMethod.IMAGE_SIZE,
|
||||
[filePath],
|
||||
{
|
||||
|
@@ -1,18 +0,0 @@
|
||||
import http from 'https'
|
||||
|
||||
function checkUrl(imageUrl) {
|
||||
http
|
||||
.get(imageUrl, (response) => {
|
||||
console.log(response.statusCode)
|
||||
})
|
||||
.on('error', (e) => {
|
||||
console.log(e)
|
||||
})
|
||||
}
|
||||
|
||||
checkUrl(
|
||||
'https://gchat.qpic.cn/download?appid=1407&fileid=CgoxMzMyNTI0MjIxEhRrdaUgQP5MjweWa4uR8pviUDaGQhjcxQUg_wooiYTj39fphQNQgL2jAQ&spec=0&rkey=CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64',
|
||||
)
|
||||
checkUrl(
|
||||
'https://multimedia.nt.qq.com.cn/download?appid=1407&fileid=CgoxMzMyNTI0MjIxEhRrdaUgQP5MjweWa4uR8pviUDaGQhjcxQUg_wooiYTj39fphQNQgL2jAQ&spec=0&rkey=CAQSKAB6JWENi5LMk0kc62l8Pm3Jn1dsLZHyRLAnNmHGoZ3y_gDZPqZt-64',
|
||||
)
|
Reference in New Issue
Block a user