diff --git a/packages/cli/src/lib/setup/setupUpload.ts b/packages/cli/src/lib/setup/setupUpload.ts index c02b9bc82b..5967845571 100644 --- a/packages/cli/src/lib/setup/setupUpload.ts +++ b/packages/cli/src/lib/setup/setupUpload.ts @@ -392,7 +392,6 @@ export class Upload { isAdmin: boolean, files: string[], id: string, - rev: any, logger: Logger | typeof console ): Promise { const uploadID = `system.adapter.${adapter}.upload`; @@ -442,18 +441,8 @@ export class Upload { } try { - await new Promise((resolve, reject) => { - const stream = fs.createReadStream(file); - stream.on('error', e => reject(e)); - stream.pipe( - this.objects.insert(id, attName, null, mimeType || {}, { rev }, err => { - if (err) { - console.log(err); - } - resolve(); - }) - ); - }); + const content = await fs.readFile(file); + await this.objects.writeFileAsync(id, attName, content, { mimeType: mimeType || undefined }); } catch (e) { console.error(`Error: Cannot upload ${file}: ${e.message}`); } @@ -627,11 +616,9 @@ export class Upload { if (!isAdmin) { await this.checkRestartOther(adapter); await new Promise(resolve => setTimeout(() => resolve(), 25)); - // @ts-expect-error TODO rev is not required and should not exist on an object? - await this.upload(adapter, isAdmin, files, id, result?.rev, logger); + await this.upload(adapter, isAdmin, files, id, logger); } else { - // @ts-expect-error TODO rev is not required and should not exist on an object? - await this.upload(adapter, isAdmin, files, id, result?.rev, logger); + await this.upload(adapter, isAdmin, files, id, logger); } } return adapter; diff --git a/packages/db-objects-redis/src/lib/objects/objectsInRedisClient.ts b/packages/db-objects-redis/src/lib/objects/objectsInRedisClient.ts index e73098a1bd..c2050524fb 100644 --- a/packages/db-objects-redis/src/lib/objects/objectsInRedisClient.ts +++ b/packages/db-objects-redis/src/lib/objects/objectsInRedisClient.ts @@ -15,13 +15,7 @@ import path from 'path'; import crypto from 'crypto'; import { isDeepStrictEqual } from 'util'; import deepClone from 'deep-clone'; -import type { - ACLObject, - FileObject, - CheckFileRightsCallback, - GetUserGroupPromiseReturn, - WMStrm -} from './objectsUtils.js'; +import type { ACLObject, FileObject, CheckFileRightsCallback, GetUserGroupPromiseReturn } from './objectsUtils.js'; import * as utils from './objectsUtils.js'; import semver from 'semver'; import * as CONSTS from './constants'; @@ -1028,17 +1022,6 @@ export class ObjectsInRedisClient { }); } - insert( - id: string, - attName: string, - ignore: any, - options: string | Record, - obj: any, - callback: (err?: Error | null) => void - ): WMStrm { - return utils.insert(this, id, attName, ignore, options, obj, callback); - } - private async _writeFile( id: string, name: string, diff --git a/packages/db-objects-redis/src/lib/objects/objectsUtils.ts b/packages/db-objects-redis/src/lib/objects/objectsUtils.ts index d63c219175..326f4b20f3 100644 --- a/packages/db-objects-redis/src/lib/objects/objectsUtils.ts +++ b/packages/db-objects-redis/src/lib/objects/objectsUtils.ts @@ -7,8 +7,7 @@ * */ -import { Writable, type WritableOptions } from 'stream'; -import path from 'path'; +import path from 'node:path'; import deepClone from 'deep-clone'; import { tools } from '@iobroker/db-base'; import * as CONSTS from './constants'; @@ -20,7 +19,6 @@ export const REG_CHECK_ID = CONSTS.REG_CHECK_ID; const USER_STARTS_WITH = CONSTS.USER_STARTS_WITH; const GROUP_STARTS_WITH = CONSTS.GROUP_STARTS_WITH; -const memStore: Record = {}; export interface FileMimeInformation { /** the mime type, of the file */ @@ -126,69 +124,6 @@ export function getMimeType(ext: string, isTextData: boolean): FileMimeInformati } } -/** - * Writable memory stream - */ -export class WMStrm extends Writable { - private readonly key: string; - - constructor(key: string, options: WritableOptions) { - super(options); // init super - this.key = key; // save key - memStore[key] = Buffer.alloc(0); // empty - } - - _write(chunk: string | Buffer, enc: BufferEncoding, cb: () => void): void { - if (chunk) { - // our memory store stores things in buffers - const buffer = Buffer.isBuffer(chunk) - ? chunk // already is Buffer use it - : Buffer.from(chunk, enc); // string, convert - - // concatenate to the buffer already there - if (!memStore[this.key]) { - memStore[this.key] = Buffer.alloc(0); - console.log(`memstore for ${this.key} is null`); - } - memStore[this.key] = Buffer.concat([memStore[this.key], buffer]); - } - if (!cb) { - throw new Error('Callback is empty'); - } - cb(); - } -} - -export function insert( - objects: any, - id: string, - attName: string, - _ignore: any, - options: Record | string, - _obj: any, - callback: (err?: Error | null) => void -): WMStrm { - if (typeof options === 'string') { - options = { mimeType: options }; - } - - // return pipe for write into redis - const strm = new WMStrm(`${id}/${attName}`, {}); - strm.on('finish', () => { - let error: null | string = null; - if (!memStore[`${id}/${attName}`]) { - error = `File ${id} / ${attName} is empty`; - } - objects.writeFile(id, attName, memStore[`${id}/${attName}`] || '', options, () => { - if (memStore[`${id}/${attName}`] !== undefined) { - delete memStore[`${id}/${attName}`]; - } - return tools.maybeCallbackWithError(callback, error); - }); - }); - return strm; -} - export function checkFile( fileOptions: Record, options: Record,