diff --git a/backend/__tests__/e2e/uploads/files.spec.ts b/backend/__tests__/e2e/uploads/files.spec.ts index acb917cc..fc45320a 100644 --- a/backend/__tests__/e2e/uploads/files.spec.ts +++ b/backend/__tests__/e2e/uploads/files.spec.ts @@ -38,6 +38,7 @@ import { import { FileGateway } from '../../../src/services/dsn/fileGateway/index.js' import { jest } from '@jest/globals' import { downloadService } from '../../../src/services/download/index.js' +import { handleArchivedObjects } from '../../../src/services/upload/nodeRemover/index.js' const files = [ { @@ -315,14 +316,17 @@ files.map((file, index) => { }) it('should be able to archive the object', async () => { - await ObjectUseCases.markAsArchived(cid) + await handleArchivedObjects() const metadata = await metadataRepository.getMetadata(cid) expect(metadata).not.toBeNull() expect(metadata?.is_archived).toBe(true) + + expect(memoryDownloadCache.has(cid)).toBe(true) + expect(await databaseDownloadCache.has(cid)).toBe(true) }) - it('should be able to remove the nodes', async () => { + it('should be able to downloaded from gateway', async () => { await databaseDownloadCache.clear() await memoryDownloadCache.clear() diff --git a/backend/migrations/20250120190642-remove-user-management-fks.js b/backend/migrations/20250120190642-remove-user-management-fks.js index 49eb24b4..49719b97 100644 --- a/backend/migrations/20250120190642-remove-user-management-fks.js +++ b/backend/migrations/20250120190642-remove-user-management-fks.js @@ -44,7 +44,6 @@ exports.down = function (db) { return new Promise(function (resolve, reject) { fs.readFile(filePath, { encoding: 'utf-8' }, function (err, data) { if (err) return reject(err) - console.log('received data: ' + data) resolve(data) }) diff --git a/backend/src/services/download/databaseDownloadCache/index.ts b/backend/src/services/download/databaseDownloadCache/index.ts index 238bd550..7d8430af 100644 --- a/backend/src/services/download/databaseDownloadCache/index.ts +++ b/backend/src/services/download/databaseDownloadCache/index.ts @@ -73,10 +73,10 @@ const get = async function* (cid: string): AsyncIterable { } } -const has = async (cid: string) => { +const has = async (cid: string): Promise => { const entry = await registryRepository.getEntry(cid) - return !!entry + return Boolean(entry).valueOf() } export const clear = async () => { diff --git a/backend/src/services/upload/nodeRemover/index.ts b/backend/src/services/upload/nodeRemover/index.ts index 3d92b6da..b71658ea 100644 --- a/backend/src/services/upload/nodeRemover/index.ts +++ b/backend/src/services/upload/nodeRemover/index.ts @@ -1,12 +1,13 @@ import { ObjectUseCases } from '../../../useCases/index.js' import { safeCallback } from '../../../utils/safe.js' +import { downloadService } from '../../download/index.js' const state = { executing: false, time: 10_000, } -const handleArchivedObjects = safeCallback(async () => { +export const handleArchivedObjects = safeCallback(async () => { if (state.executing) { return } @@ -19,6 +20,7 @@ const handleArchivedObjects = safeCallback(async () => { for (const cid of cids) { const hasAllNodesArchived = await ObjectUseCases.hasAllNodesArchived(cid) if (hasAllNodesArchived) { + await downloadService.download(cid) await ObjectUseCases.markAsArchived(cid) } }