mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-23 05:33:08 +02:00
Use hashed filename for exists check
This commit is contained in:
parent
265bcf54b0
commit
0bb0d69543
1 changed files with 6 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
import * as fs from 'node:fs';
|
import * as fs from 'node:fs';
|
||||||
import * as vm from 'node:vm';
|
import * as vm from 'node:vm';
|
||||||
|
import * as crypto from 'node:crypto';
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { ZipReader } from 'slacc';
|
import { ZipReader } from 'slacc';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
|
@ -469,7 +470,10 @@ export class ImportNotesProcessorService {
|
||||||
|
|
||||||
for await (const file of post.object.attachment) {
|
for await (const file of post.object.attachment) {
|
||||||
const slashdex = file.url.lastIndexOf('/');
|
const slashdex = file.url.lastIndexOf('/');
|
||||||
const name = file.url.substring(slashdex + 1);
|
const filename = file.url.substring(slashdex + 1);
|
||||||
|
const hash = crypto.createHash('md5').setEncoding('hex');
|
||||||
|
const urlHash = hash.update(file.url).digest('base64');
|
||||||
|
const name = `${urlHash}-${filename}`;
|
||||||
const [filePath, cleanup] = await createTemp();
|
const [filePath, cleanup] = await createTemp();
|
||||||
|
|
||||||
const exists = await this.driveFilesRepository.findOneBy({ name: name, userId: user.id }) ?? await this.driveFilesRepository.findOneBy({ name: name, userId: user.id, folderId: pleroFolder?.id });
|
const exists = await this.driveFilesRepository.findOneBy({ name: name, userId: user.id }) ?? await this.driveFilesRepository.findOneBy({ name: name, userId: user.id, folderId: pleroFolder?.id });
|
||||||
|
@ -484,6 +488,7 @@ export class ImportNotesProcessorService {
|
||||||
user: user,
|
user: user,
|
||||||
path: filePath,
|
path: filePath,
|
||||||
name: name,
|
name: name,
|
||||||
|
comment: file.name,
|
||||||
folderId: pleroFolder?.id,
|
folderId: pleroFolder?.id,
|
||||||
});
|
});
|
||||||
files.push(driveFile);
|
files.push(driveFile);
|
||||||
|
|
Loading…
Reference in a new issue