Fix undefined filename
This commit is contained in:
parent
fabe4df6c9
commit
3d1093c265
24
src/environment/mimeTypeMap.ts
Normal file
24
src/environment/mimeTypeMap.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
export const EXTENSION_MIME_TYPE_MAP: {[ext in MTFileExtension]: MTMimeType} = {
|
||||||
|
pdf: 'application/pdf',
|
||||||
|
tgv: 'application/x-tgwallpattern',
|
||||||
|
tgs: 'application/x-tgsticker',
|
||||||
|
json: 'application/json',
|
||||||
|
wav: 'audio/wav',
|
||||||
|
mp3: 'audio/mpeg',
|
||||||
|
ogg: 'audio/ogg',
|
||||||
|
jpeg: 'image/jpeg',
|
||||||
|
jpg: 'image/jpeg',
|
||||||
|
png: 'image/png',
|
||||||
|
gif: 'image/gif',
|
||||||
|
webp: 'image/webp',
|
||||||
|
mp4: 'video/mp4',
|
||||||
|
webm: 'video/webm',
|
||||||
|
mov: 'video/quicktime',
|
||||||
|
svg: 'image/svg+xml'
|
||||||
|
};
|
||||||
|
|
||||||
|
export const MIME_TYPE_EXTENSION_MAP: {[mimeType in MTMimeType]?: MTFileExtension} = {};
|
||||||
|
|
||||||
|
for(const ext in EXTENSION_MIME_TYPE_MAP) {
|
||||||
|
MIME_TYPE_EXTENSION_MAP[EXTENSION_MIME_TYPE_MAP[ext as MTFileExtension]] = ext as MTFileExtension;
|
||||||
|
}
|
8
src/global.d.ts
vendored
8
src/global.d.ts
vendored
@ -23,6 +23,14 @@ declare global {
|
|||||||
type Long = string | number;
|
type Long = string | number;
|
||||||
type MTLong = string;
|
type MTLong = string;
|
||||||
|
|
||||||
|
type MTMimeType = 'video/quicktime' | 'image/gif' | 'image/jpeg' | 'application/pdf' |
|
||||||
|
'video/mp4' | 'image/webp' | 'audio/mpeg' | 'audio/ogg' | 'application/octet-stream' |
|
||||||
|
'application/x-tgsticker' | 'video/webm' | 'image/svg+xml' | 'image/png' | 'application/json' |
|
||||||
|
'application/x-tgwallpattern' | 'audio/wav';
|
||||||
|
|
||||||
|
type MTFileExtension = 'mov' | 'gif' | 'pdf' | 'jpg' | 'jpeg' | 'wav' |
|
||||||
|
'tgv' | 'tgs' | 'svg' | 'mp4' | 'webm' | 'webp' | 'mp3' | 'ogg' | 'json' | 'png';
|
||||||
|
|
||||||
type ApiFileManagerError = 'DOWNLOAD_CANCELED' | 'UPLOAD_CANCELED' | 'FILE_TOO_BIG' | 'REFERENCE_IS_NOT_REFRESHED';
|
type ApiFileManagerError = 'DOWNLOAD_CANCELED' | 'UPLOAD_CANCELED' | 'FILE_TOO_BIG' | 'REFERENCE_IS_NOT_REFRESHED';
|
||||||
type StorageError = 'STORAGE_OFFLINE' | 'NO_ENTRY_FOUND' | 'IDB_CREATE_TIMEOUT';
|
type StorageError = 'STORAGE_OFFLINE' | 'NO_ENTRY_FOUND' | 'IDB_CREATE_TIMEOUT';
|
||||||
type ReferenceError = 'NO_NEW_CONTEXT';
|
type ReferenceError = 'NO_NEW_CONTEXT';
|
||||||
|
12
src/layer.d.ts
vendored
12
src/layer.d.ts
vendored
@ -3307,7 +3307,6 @@ export namespace Document {
|
|||||||
access_hash: string | number,
|
access_hash: string | number,
|
||||||
file_reference: Uint8Array | number[],
|
file_reference: Uint8Array | number[],
|
||||||
date: number,
|
date: number,
|
||||||
mime_type: string,
|
|
||||||
video_thumbs?: Array<VideoSize>,
|
video_thumbs?: Array<VideoSize>,
|
||||||
dc_id: number,
|
dc_id: number,
|
||||||
attributes: Array<DocumentAttribute>,
|
attributes: Array<DocumentAttribute>,
|
||||||
@ -3326,7 +3325,8 @@ export namespace Document {
|
|||||||
}>,
|
}>,
|
||||||
animated?: boolean,
|
animated?: boolean,
|
||||||
supportsStreaming?: boolean,
|
supportsStreaming?: boolean,
|
||||||
size?: number
|
size?: number,
|
||||||
|
mime_type?: MTMimeType
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5924,20 +5924,20 @@ export namespace WebDocument {
|
|||||||
url: string,
|
url: string,
|
||||||
access_hash: string | number,
|
access_hash: string | number,
|
||||||
size: number,
|
size: number,
|
||||||
mime_type: string,
|
|
||||||
attributes: Array<DocumentAttribute>,
|
attributes: Array<DocumentAttribute>,
|
||||||
h?: number,
|
h?: number,
|
||||||
w?: number
|
w?: number,
|
||||||
|
mime_type?: MTMimeType
|
||||||
};
|
};
|
||||||
|
|
||||||
export type webDocumentNoProxy = {
|
export type webDocumentNoProxy = {
|
||||||
_: 'webDocumentNoProxy',
|
_: 'webDocumentNoProxy',
|
||||||
url: string,
|
url: string,
|
||||||
size: number,
|
size: number,
|
||||||
mime_type: string,
|
|
||||||
attributes: Array<DocumentAttribute>,
|
attributes: Array<DocumentAttribute>,
|
||||||
h?: number,
|
h?: number,
|
||||||
w?: number
|
w?: number,
|
||||||
|
mime_type?: MTMimeType
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,17 +24,12 @@ import getDocumentInputFileLocation from './utils/docs/getDocumentInputFileLocat
|
|||||||
import getDocumentURL from './utils/docs/getDocumentURL';
|
import getDocumentURL from './utils/docs/getDocumentURL';
|
||||||
import type {ThumbCache} from '../storages/thumbs';
|
import type {ThumbCache} from '../storages/thumbs';
|
||||||
import makeError from '../../helpers/makeError';
|
import makeError from '../../helpers/makeError';
|
||||||
|
import {EXTENSION_MIME_TYPE_MAP} from '../../environment/mimeTypeMap';
|
||||||
|
|
||||||
export type MyDocument = Document.document;
|
export type MyDocument = Document.document;
|
||||||
|
|
||||||
// TODO: если залить картинку файлом, а потом перезайти в диалог - превьюшка заново скачается
|
// TODO: если залить картинку файлом, а потом перезайти в диалог - превьюшка заново скачается
|
||||||
|
|
||||||
const EXTENSION_MIME_TYPE_MAP = {
|
|
||||||
mov: 'video/quicktime',
|
|
||||||
gif: 'image/gif',
|
|
||||||
pdf: 'application/pdf'
|
|
||||||
};
|
|
||||||
|
|
||||||
type WallPaperId = WallPaper.wallPaper['id'];
|
type WallPaperId = WallPaper.wallPaper['id'];
|
||||||
|
|
||||||
let uploadWallPaperTempId = 0;
|
let uploadWallPaperTempId = 0;
|
||||||
@ -340,7 +335,7 @@ export class AppDocsManager extends AppManager {
|
|||||||
dc_id: 0,
|
dc_id: 0,
|
||||||
file_reference: [],
|
file_reference: [],
|
||||||
id,
|
id,
|
||||||
mime_type: file.type,
|
mime_type: file.type as MTMimeType,
|
||||||
size: file.size,
|
size: file.size,
|
||||||
date: Date.now() / 1000,
|
date: Date.now() / 1000,
|
||||||
pFlags: {},
|
pFlags: {},
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type {MyDocument} from './appDocsManager';
|
import type {MyDocument} from './appDocsManager';
|
||||||
|
import type {DownloadOptions} from '../mtproto/apiFileManager';
|
||||||
import {Document, InputFileLocation, InputStickerSet, MessagesAllStickers, MessagesFavedStickers, MessagesFeaturedStickers, MessagesFoundStickerSets, MessagesRecentStickers, MessagesStickers, MessagesStickerSet, PhotoSize, StickerPack, StickerSet, StickerSetCovered, Update} from '../../layer';
|
import {Document, InputFileLocation, InputStickerSet, MessagesAllStickers, MessagesFavedStickers, MessagesFeaturedStickers, MessagesFoundStickerSets, MessagesRecentStickers, MessagesStickers, MessagesStickerSet, PhotoSize, StickerPack, StickerSet, StickerSetCovered, Update} from '../../layer';
|
||||||
import {Modify} from '../../types';
|
import {Modify} from '../../types';
|
||||||
import AppStorage from '../storage';
|
import AppStorage from '../storage';
|
||||||
@ -384,7 +385,7 @@ export class AppStickersManager extends AppManager {
|
|||||||
this.storage.set({[id]: stickerSet}, !needSave);
|
this.storage.set({[id]: stickerSet}, !needSave);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getStickerSetThumbDownloadOptions(stickerSet: StickerSet.stickerSet) {
|
public getStickerSetThumbDownloadOptions(stickerSet: StickerSet.stickerSet): DownloadOptions {
|
||||||
const thumb = stickerSet.thumbs.find((thumb) => thumb._ === 'photoSize') as PhotoSize.photoSize;
|
const thumb = stickerSet.thumbs.find((thumb) => thumb._ === 'photoSize') as PhotoSize.photoSize;
|
||||||
const dcId = stickerSet.thumb_dc_id;
|
const dcId = stickerSet.thumb_dc_id;
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import getDocumentInputFileLocation from './getDocumentInputFileLocation';
|
|||||||
export default function getDocumentDownloadOptions(doc: Document.document, thumb?: PhotoSize.photoSize | VideoSize, queueId?: number, onlyCache?: boolean): DownloadOptions {
|
export default function getDocumentDownloadOptions(doc: Document.document, thumb?: PhotoSize.photoSize | VideoSize, queueId?: number, onlyCache?: boolean): DownloadOptions {
|
||||||
const inputFileLocation = getDocumentInputFileLocation(doc, thumb?.type);
|
const inputFileLocation = getDocumentInputFileLocation(doc, thumb?.type);
|
||||||
|
|
||||||
let mimeType: string;
|
let mimeType: MTMimeType;
|
||||||
if(thumb?._ === 'photoSize') {
|
if(thumb?._ === 'photoSize') {
|
||||||
mimeType = doc.sticker ? 'image/webp' : 'image/jpeg'/* doc.mime_type */;
|
mimeType = doc.sticker ? 'image/webp' : 'image/jpeg'/* doc.mime_type */;
|
||||||
} else {
|
} else {
|
||||||
|
@ -18,7 +18,7 @@ export default function getPhotoDownloadOptions(photo: MyPhoto | MyDocument, pho
|
|||||||
}
|
}
|
||||||
|
|
||||||
// maybe it's a thumb
|
// maybe it's a thumb
|
||||||
const isPhoto = (photoSize._ === 'photoSize' || photoSize._ === 'photoSizeProgressive') && photo.access_hash && photo.file_reference;
|
const isPhoto = !!((photoSize._ === 'photoSize' || photoSize._ === 'photoSizeProgressive') && photo.access_hash && photo.file_reference);
|
||||||
const location: InputFileLocation.inputPhotoFileLocation | InputFileLocation.inputDocumentFileLocation = {
|
const location: InputFileLocation.inputPhotoFileLocation | InputFileLocation.inputDocumentFileLocation = {
|
||||||
_: isDocument ? 'inputDocumentFileLocation' : 'inputPhotoFileLocation',
|
_: isDocument ? 'inputDocumentFileLocation' : 'inputPhotoFileLocation',
|
||||||
id: photo.id,
|
id: photo.id,
|
||||||
@ -31,6 +31,7 @@ export default function getPhotoDownloadOptions(photo: MyPhoto | MyDocument, pho
|
|||||||
dcId: photo.dc_id,
|
dcId: photo.dc_id,
|
||||||
location,
|
location,
|
||||||
size: isPhoto ? (photoSize as PhotoSize.photoSize).size : undefined,
|
size: isPhoto ? (photoSize as PhotoSize.photoSize).size : undefined,
|
||||||
|
mimeType: 'image/jpeg',
|
||||||
queueId,
|
queueId,
|
||||||
onlyCache
|
onlyCache
|
||||||
};
|
};
|
||||||
|
@ -40,6 +40,7 @@ import readBlobAsUint8Array from '../../helpers/blob/readBlobAsUint8Array';
|
|||||||
import DownloadStorage from '../files/downloadStorage';
|
import DownloadStorage from '../files/downloadStorage';
|
||||||
import copy from '../../helpers/object/copy';
|
import copy from '../../helpers/object/copy';
|
||||||
import indexOfAndSplice from '../../helpers/array/indexOfAndSplice';
|
import indexOfAndSplice from '../../helpers/array/indexOfAndSplice';
|
||||||
|
import {MIME_TYPE_EXTENSION_MAP} from '../../environment/mimeTypeMap';
|
||||||
|
|
||||||
type Delayed = {
|
type Delayed = {
|
||||||
offset: number,
|
offset: number,
|
||||||
@ -52,7 +53,7 @@ export type DownloadOptions = {
|
|||||||
location: InputFileLocation | InputWebFileLocation,
|
location: InputFileLocation | InputWebFileLocation,
|
||||||
size?: number,
|
size?: number,
|
||||||
fileName?: string,
|
fileName?: string,
|
||||||
mimeType?: string,
|
mimeType?: MTMimeType,
|
||||||
limitPart?: number,
|
limitPart?: number,
|
||||||
queueId?: number,
|
queueId?: number,
|
||||||
onlyCache?: boolean,
|
onlyCache?: boolean,
|
||||||
@ -428,7 +429,7 @@ export class ApiFileManager extends AppManager {
|
|||||||
return this.uploadPromises[fileName];
|
return this.uploadPromises[fileName];
|
||||||
}
|
}
|
||||||
|
|
||||||
private getConvertMethod(mimeType: string) {
|
private getConvertMethod(mimeType: MTMimeType) {
|
||||||
let process: ApiFileManager['uncompressTGS'] | ApiFileManager['convertWebp'];
|
let process: ApiFileManager['uncompressTGS'] | ApiFileManager['convertWebp'];
|
||||||
if(mimeType === 'application/x-tgwallpattern') {
|
if(mimeType === 'application/x-tgwallpattern') {
|
||||||
process = this.uncompressTGV;
|
process = this.uncompressTGV;
|
||||||
@ -558,8 +559,17 @@ export class ApiFileManager extends AppManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(downloadStorage) {
|
if(downloadStorage) {
|
||||||
|
let downloadFileName = options.fileName; // it's doc file_name
|
||||||
|
if(!downloadFileName) {
|
||||||
|
downloadFileName = cacheFileName;
|
||||||
|
const ext = MIME_TYPE_EXTENSION_MAP[options.mimeType];
|
||||||
|
if(ext) {
|
||||||
|
downloadFileName += '.' + ext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
downloadPrepared = downloadStorage.prepareWriting({
|
downloadPrepared = downloadStorage.prepareWriting({
|
||||||
fileName: options.fileName, // it's doc file_name
|
fileName: downloadFileName,
|
||||||
downloadId,
|
downloadId,
|
||||||
size: possibleSize
|
size: possibleSize
|
||||||
});
|
});
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
{"name": "stickerThumbConverted", "type": "true"},
|
{"name": "stickerThumbConverted", "type": "true"},
|
||||||
{"name": "animated", "type": "boolean"},
|
{"name": "animated", "type": "boolean"},
|
||||||
{"name": "supportsStreaming", "type": "boolean"},
|
{"name": "supportsStreaming", "type": "boolean"},
|
||||||
{"name": "size", "type": "number"}
|
{"name": "size", "type": "number"},
|
||||||
|
{"name": "mime_type", "type": "MTMimeType"}
|
||||||
]
|
]
|
||||||
}, {
|
}, {
|
||||||
"predicate": "photoSizeProgressive",
|
"predicate": "photoSizeProgressive",
|
||||||
@ -349,12 +350,14 @@
|
|||||||
"predicate": "webDocument",
|
"predicate": "webDocument",
|
||||||
"params": [
|
"params": [
|
||||||
{"name": "h", "type": "number"},
|
{"name": "h", "type": "number"},
|
||||||
{"name": "w", "type": "number"}
|
{"name": "w", "type": "number"},
|
||||||
|
{"name": "mime_type", "type": "MTMimeType"}
|
||||||
]
|
]
|
||||||
}, {
|
}, {
|
||||||
"predicate": "webDocumentNoProxy",
|
"predicate": "webDocumentNoProxy",
|
||||||
"params": [
|
"params": [
|
||||||
{"name": "h", "type": "number"},
|
{"name": "h", "type": "number"},
|
||||||
{"name": "w", "type": "number"}
|
{"name": "w", "type": "number"},
|
||||||
|
{"name": "mime_type", "type": "MTMimeType"}
|
||||||
]
|
]
|
||||||
}]
|
}]
|
Loading…
x
Reference in New Issue
Block a user