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的文件夹
|
// 上传文件到QQ的文件夹
|
||||||
async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC, elementSubType = 0) {
|
async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC, elementSubType = 0) {
|
||||||
const fileMd5 = await calculateFileMD5(filePath)
|
const fileMd5 = await calculateFileMD5(filePath)
|
||||||
let ext = (await this.getFileType(filePath))?.ext || ''
|
let fileName = path.basename(filePath)
|
||||||
if (ext) {
|
if (!fileName.includes('.')) {
|
||||||
ext = '.' + ext
|
const ext = (await this.getFileType(filePath))?.ext
|
||||||
|
fileName += ext ? '.' + ext : ''
|
||||||
}
|
}
|
||||||
let fileName = `${path.basename(filePath)}`
|
const mediaPath = await invoke(NTMethod.MEDIA_FILE_PATH, [{
|
||||||
if (fileName.indexOf('.') === -1) {
|
path_info: {
|
||||||
fileName += ext
|
|
||||||
}
|
|
||||||
const session = getSession()
|
|
||||||
let mediaPath: string
|
|
||||||
if (session) {
|
|
||||||
mediaPath = session?.getMsgService().getRichMediaFilePathForGuild({
|
|
||||||
md5HexStr: fileMd5,
|
md5HexStr: fileMd5,
|
||||||
fileName: fileName,
|
fileName: fileName,
|
||||||
elementType: elementType,
|
elementType: elementType,
|
||||||
@@ -94,22 +89,9 @@ export class NTQQFileApi extends Service {
|
|||||||
thumbSize: 0,
|
thumbSize: 0,
|
||||||
needCreate: true,
|
needCreate: true,
|
||||||
downloadType: 1,
|
downloadType: 1,
|
||||||
file_uuid: ''
|
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: '',
|
|
||||||
},
|
|
||||||
}])
|
|
||||||
}
|
|
||||||
await copyFile(filePath, mediaPath)
|
await copyFile(filePath, mediaPath)
|
||||||
const fileSize = (await stat(filePath)).size
|
const fileSize = (await stat(filePath)).size
|
||||||
return {
|
return {
|
||||||
@@ -117,7 +99,6 @@ export class NTQQFileApi extends Service {
|
|||||||
fileName,
|
fileName,
|
||||||
path: mediaPath,
|
path: mediaPath,
|
||||||
fileSize,
|
fileSize,
|
||||||
ext
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +157,11 @@ export class NTQQFileApi extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getImageSize(filePath: string) {
|
async getImageSize(filePath: string) {
|
||||||
return await invoke<{ width: number; height: number }>(
|
return await invoke<{
|
||||||
|
width: number
|
||||||
|
height: number
|
||||||
|
type: string
|
||||||
|
}>(
|
||||||
NTMethod.IMAGE_SIZE,
|
NTMethod.IMAGE_SIZE,
|
||||||
[filePath],
|
[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