Skip to content

Commit 7ec6621

Browse files
committed
dev: make code more compatible with migration branch
1 parent 90967ab commit 7ec6621

File tree

1 file changed

+52
-45
lines changed

1 file changed

+52
-45
lines changed

src/backend/src/services/AppIconService.js

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -128,54 +128,61 @@ class AppIconService extends BaseService {
128128
// Listen for new app icons
129129
const svc_event = this.services.get('event');
130130
svc_event.on('app.new-icon', async (_, data) => {
131-
// Writing icons as the system user
132-
const icon_jobs = [];
133-
for ( const size of ICON_SIZES ) {
134-
icon_jobs.push((async () => {
135-
await svc_su.sudo(async () => {
136-
const filename = `${data.app_uid}-${size}.png`;
137-
console.log('FILENAME', filename);
138-
const data_url = data.data_url;
139-
const [metadata, base64] = data_url.split(',');
140-
const input = Buffer.from(base64, 'base64');
141-
142-
const sharp_instance = this.get_sharp({
143-
metadata,
144-
input,
145-
});
146-
147-
// NOTE: A stream would be more ideal than a buffer here
148-
// but we have no way of knowing the output size
149-
// before we finish processing the image.
150-
const output = await sharp_instance
151-
.resize(size)
152-
.png()
153-
.toBuffer();
154-
155-
const sys_actor = await svc_su.get_system_actor();
156-
const hl_write = new HLWrite();
157-
await hl_write.run({
158-
destination_or_parent: dir_app_icons,
159-
specified_name: filename,
160-
overwrite: true,
161-
actor: sys_actor,
162-
user: sys_actor.type.user,
163-
no_thumbnail: true,
164-
file: {
165-
size: output.length,
166-
name: filename,
167-
mimetype: 'image/png',
168-
type: 'image/png',
169-
stream: buffer_to_stream(output),
170-
},
171-
});
172-
})
173-
})());
174-
}
175-
await Promise.all(icon_jobs);
131+
await this.create_app_icons({ data });
176132
});
177133
}
178134

135+
async create_app_icons ({ data }) {
136+
const svc_su = this.services.get('su');
137+
const dir_app_icons = await this.get_app_icons();
138+
139+
// Writing icons as the system user
140+
const icon_jobs = [];
141+
for ( const size of ICON_SIZES ) {
142+
icon_jobs.push((async () => {
143+
await svc_su.sudo(async () => {
144+
const filename = `${data.app_uid}-${size}.png`;
145+
console.log('FILENAME', filename);
146+
const data_url = data.data_url;
147+
const [metadata, base64] = data_url.split(',');
148+
const input = Buffer.from(base64, 'base64');
149+
150+
const sharp_instance = this.get_sharp({
151+
metadata,
152+
input,
153+
});
154+
155+
// NOTE: A stream would be more ideal than a buffer here
156+
// but we have no way of knowing the output size
157+
// before we finish processing the image.
158+
const output = await sharp_instance
159+
.resize(size)
160+
.png()
161+
.toBuffer();
162+
163+
const sys_actor = await svc_su.get_system_actor();
164+
const hl_write = new HLWrite();
165+
await hl_write.run({
166+
destination_or_parent: dir_app_icons,
167+
specified_name: filename,
168+
overwrite: true,
169+
actor: sys_actor,
170+
user: sys_actor.type.user,
171+
no_thumbnail: true,
172+
file: {
173+
size: output.length,
174+
name: filename,
175+
mimetype: 'image/png',
176+
type: 'image/png',
177+
stream: buffer_to_stream(output),
178+
},
179+
});
180+
})
181+
})());
182+
}
183+
await Promise.all(icon_jobs);
184+
}
185+
179186
async _init () {
180187
}
181188
}

0 commit comments

Comments
 (0)