@@ -307,17 +307,19 @@ export class Files {
307307 const files = await prisma . files . findMany ( {
308308 where : {
309309 AND : [
310- {
311- name : {
312- startsWith : body . name . replace ( / \. p a r t 0 * \d + $ / , '' )
313- }
314- } ,
315- {
316- user_id : req . user ?. id
317- } ,
318- {
319- parent_id : source . parent_id
320- } ,
310+ { name : source . name . endsWith ( '.part001' ) ? { startsWith : source . name . replace ( / \. p a r t 0 * \d + $ / , '.part' ) } : source . name } ,
311+ { user_id : req . user ?. id } ,
312+ { parent_id : source . parent_id } ,
313+ ]
314+ }
315+ } )
316+
317+ const countExists = await prisma . files . count ( {
318+ where : {
319+ AND : [
320+ { name : source . name . endsWith ( '.part001' ) ? { startsWith : source . name . replace ( / \. p a r t 0 * \d + $ / , '' ) , endsWith : '.part001' } : { startsWith : source . name } } ,
321+ { user_id : req . user ?. id } ,
322+ { parent_id : body . parent_id }
321323 ]
322324 }
323325 } )
@@ -328,8 +330,8 @@ export class Files {
328330 const { forward_info : forwardInfo , message_id : messageId , mime_type : mimeType } = file
329331 let peerFrom : Api . InputPeerChannel | Api . InputPeerUser | Api . InputPeerChat
330332 let peerTo : Api . InputPeerChannel | Api . InputPeerUser | Api . InputPeerChat
331- const [ type , peerId , _id , accessHash ] = forwardInfo ?. split ( '/' ) ?? [ ]
332333 if ( forwardInfo && forwardInfo . match ( / ^ c h a n n e l \/ / gi) ) {
334+ const [ type , peerId , _id , accessHash ] = forwardInfo ?. split ( '/' ) ?? [ ]
333335 if ( type === 'channel' ) {
334336 peerFrom = new Api . InputPeerChannel ( {
335337 channelId : bigInt ( peerId ) ,
@@ -343,8 +345,8 @@ export class Files {
343345 chatId : bigInt ( peerId ) } )
344346 }
345347 }
348+ const [ type , peerId , _ , accessHash ] = ( ( req . user . settings as Prisma . JsonObject ) . saved_location as string ) . split ( '/' )
346349 if ( ( req . user . settings as Prisma . JsonObject ) ?. saved_location ) {
347- const [ type , peerId , _ , accessHash ] = ( ( req . user . settings as Prisma . JsonObject ) . saved_location as string ) . split ( '/' )
348350 if ( type === 'channel' ) {
349351 peerTo = new Api . InputPeerChannel ( {
350352 channelId : bigInt ( peerId ) ,
@@ -368,7 +370,7 @@ export class Files {
368370 dropAuthor : true
369371 } ) ) as any
370372
371- const newForwardInfo = forwardInfo ? `${ type } /${ peerId } /${ chat . updates [ 0 ] . id . toString ( ) } /${ accessHash } ` : null
373+ const newForwardInfo = peerTo ? `${ type } /${ peerId } /${ chat . updates [ 0 ] . id . toString ( ) } /${ accessHash } ` : null
372374 const message = {
373375 size : Number ( file . size ) ,
374376 message_id : chat . updates [ 0 ] . id . toString ( ) ,
@@ -380,7 +382,7 @@ export class Files {
380382 const response = await prisma . files . create ( {
381383 data : {
382384 ...body ,
383- name : files . length == 1 ? body . name : body . name . replace ( / \. p a r t 0 * \d + $ / , '' ) + `.part${ String ( countFiles + 1 ) . padStart ( 3 , '0' ) } ` ,
385+ name : files . length == 1 ? body . name + ` ${ countExists ? ` ( ${ countExists } )` : '' } ` : body . name . replace ( / \. p a r t 0 * \d + $ / , '' ) + ` ${ countExists ? ` ( ${ countExists } )` : '' } ` + `.part${ String ( countFiles + 1 ) . padStart ( 3 , '0' ) } ` ,
384386 ...message
385387 }
386388 } )
@@ -1065,15 +1067,16 @@ export class Files {
10651067
10661068 const getSizes = ( { size, sizes } ) => sizes ? sizes . pop ( ) : size
10671069 const size = file . media . photo ? getSizes ( file . media . photo . sizes . pop ( ) ) : file . media . document ?. size
1068- let type = file . media . photo || mimeType . match ( / ^ i m a g e / gi ) ? 'image' : null
1070+ let type = file . media . photo
10691071 if ( file . media . document ?. mimeType . match ( / ^ v i d e o / gi) || name . match ( / \. m p 4 $ / gi) || name . match ( / \. m k v $ / gi) || name . match ( / \. m o v $ / gi) ) {
10701072 type = 'video'
10711073 } else if ( file . media . document ?. mimeType . match ( / p d f $ / gi) || name . match ( / \. d o c $ / gi) || name . match ( / \. d o c x $ / gi) || name . match ( / \. x l s $ / gi) || name . match ( / \. x l s x $ / gi) ) {
10721074 type = 'document'
10731075 } else if ( file . media . document ?. mimeType . match ( / a u d i o $ / gi) || name . match ( / \. m p 3 $ / gi) || name . match ( / \. o g g $ / gi) ) {
10741076 type = 'audio'
1077+ } else if ( file . media . document ?. mimeType . match ( / ^ i m a g e / gi) || name . match ( / \. j p g $ / gi) || name . match ( / \. j p e g $ / gi) || name . match ( / \. p n g $ / gi) || name . match ( / \. g i f $ / gi) ) {
1078+ type = 'image'
10751079 }
1076-
10771080 return {
10781081 name,
10791082 message_id : file . id . toString ( ) ,
@@ -1200,7 +1203,7 @@ export class Files {
12001203 const end = ranges [ 1 ] ? ranges [ 1 ] : totalFileSize . toJSNumber ( ) - 1
12011204
12021205 const readStream = createReadStream ( filename ( ) , { start, end } )
1203- res . writeHead ( 206 , {
1206+ res . writeHead ( 200 , {
12041207 'Cache-Control' : 'public, max-age=604800' ,
12051208 'ETag' : Buffer . from ( `${ files [ 0 ] . id } :${ files [ 0 ] . message_id } ` ) . toString ( 'base64' ) ,
12061209 'Content-Range' : `bytes ${ start } -${ end } /${ totalFileSize } ` ,
@@ -1211,7 +1214,7 @@ export class Files {
12111214 } )
12121215 readStream . pipe ( res )
12131216 } else {
1214- res . writeHead ( 206 , {
1217+ res . writeHead ( 200 , {
12151218 'Cache-Control' : 'public, max-age=604800' ,
12161219 'ETag' : Buffer . from ( `${ files [ 0 ] . id } :${ files [ 0 ] . message_id } ` ) . toString ( 'base64' ) ,
12171220 'Content-Range' : `bytes */${ totalFileSize } ` ,
0 commit comments