Skip to content

Commit 3ea4929

Browse files
authored
Fixed mime type for known extensions (#2393)
* on create backup do no longer call processExit internally - because this leads to unwanted success-like code running in parallel * refactor file name * use writeJson * do not prettify the json, as we need to save space * fixed mimetype * fix test ;-)
1 parent dcc05a1 commit 3ea4929

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

packages/controller/test/lib/testFiles.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,31 @@ export function register(it: Mocha.TestFunction, expect: Chai.ExpectStatic, cont
218218
expect(file).to.be.equal(dataText);
219219
});
220220

221+
it(testName + 'writeFile with known extension should be inferred', async () => {
222+
const objId = `vis.0`;
223+
/** no extension but string content should lead to plain text */
224+
const fileName = 'testFile.json';
225+
const dataJson = { quote: "Toto, I've a feeling we're not in Kansas anymore." };
226+
const content = JSON.stringify(dataJson);
227+
// create an object of type file first
228+
await context.adapter.setForeignObjectAsync(objId, {
229+
type: 'meta',
230+
common: {
231+
name: 'Files and more',
232+
type: 'meta.user'
233+
},
234+
native: {}
235+
});
236+
237+
// now we write a file state
238+
await context.adapter.writeFileAsync(objId, fileName, content);
239+
240+
const { file, mimeType } = await context.adapter.readFileAsync(objId, fileName);
241+
242+
expect(mimeType).to.be.equal('application/json');
243+
expect(file).to.be.equal(content);
244+
});
245+
221246
it(testName + 'deleteFile', async () => {
222247
const objId = `vis.0`;
223248
const fileName = 'testFile.bin';

packages/controller/test/lib/testObjects.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ export function register(it: Mocha.TestFunction, expect: Chai.ExpectStatic, cont
414414
expect(exists).to.be.true;
415415
});
416416

417+
// TODO: here are also a few file tests, move them to testFiles.ts instead
417418
it(testName + 'should create and read file', done => {
418419
const objects = context.objects;
419420
objects.setObject(testId, { type: 'meta', native: {} } as ioBroker.SettableMetaObject, err => {

packages/db-objects-redis/src/lib/objects/objectsInRedisClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ export class ObjectsInRedisClient {
10581058

10591059
const isTextData = typeof data === 'string';
10601060

1061-
const { mimeType, isBinary } = utils.getMimeType(ext[0], isTextData);
1061+
const { mimeType, isBinary } = utils.getMimeType(ext, isTextData);
10621062

10631063
const metaID = this.getFileId(id, name, true);
10641064
if (!this.client) {

0 commit comments

Comments
 (0)