This commit is contained in:
idranme
2024-09-20 03:19:43 +08:00
parent 0f7939fe5e
commit 44febed486
2 changed files with 14 additions and 47 deletions

View File

@@ -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],
{ {

View File

@@ -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',
)