@things-factory/media 0.0.0-stage → 10.1.306

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,558 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MediaResolver = exports.MediaItemList = exports.MediaFilter = exports.MediaImageModel = exports.MediaImageQuality = exports.MediaShareRoute = exports.MediaShareFields = exports.MediaItemPatch = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const GraphQLUpload_js_1 = tslib_1.__importDefault(require("graphql-upload/GraphQLUpload.js"));
6
+ const type_graphql_1 = require("type-graphql");
7
+ const typeorm_1 = require("typeorm");
8
+ const attachment_base_1 = require("@things-factory/attachment-base");
9
+ const shell_1 = require("@things-factory/shell");
10
+ const media_item_1 = require("./media-item");
11
+ const media_purpose_1 = require("./media-purpose");
12
+ const media_service_1 = require("./media-service");
13
+ const media_use_1 = require("./media-use");
14
+ const media_ai_1 = require("./media-ai");
15
+ let MediaItemPatch = class MediaItemPatch {
16
+ };
17
+ exports.MediaItemPatch = MediaItemPatch;
18
+ tslib_1.__decorate([
19
+ (0, type_graphql_1.Field)({ nullable: true, description: 'What the picture is called' }),
20
+ tslib_1.__metadata("design:type", String)
21
+ ], MediaItemPatch.prototype, "title", void 0);
22
+ tslib_1.__decorate([
23
+ (0, type_graphql_1.Field)(type => media_item_1.MediaKind, { nullable: true, description: 'What kind of picture it is' }),
24
+ tslib_1.__metadata("design:type", String)
25
+ ], MediaItemPatch.prototype, "kind", void 0);
26
+ tslib_1.__decorate([
27
+ (0, type_graphql_1.Field)({ nullable: true, description: 'When it was taken' }),
28
+ tslib_1.__metadata("design:type", Date)
29
+ ], MediaItemPatch.prototype, "takenAt", void 0);
30
+ tslib_1.__decorate([
31
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Where it was taken' }),
32
+ tslib_1.__metadata("design:type", String)
33
+ ], MediaItemPatch.prototype, "place", void 0);
34
+ tslib_1.__decorate([
35
+ (0, type_graphql_1.Field)(type => media_item_1.MediaExposure, { nullable: true, description: 'How far it may be shown' }),
36
+ tslib_1.__metadata("design:type", String)
37
+ ], MediaItemPatch.prototype, "exposure", void 0);
38
+ tslib_1.__decorate([
39
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Whether a person confirmed how far it may be shown' }),
40
+ tslib_1.__metadata("design:type", Boolean)
41
+ ], MediaItemPatch.prototype, "exposureConfirmed", void 0);
42
+ tslib_1.__decorate([
43
+ (0, type_graphql_1.Field)(type => media_item_1.MediaOrigin, { nullable: true, description: 'Where it came from' }),
44
+ tslib_1.__metadata("design:type", String)
45
+ ], MediaItemPatch.prototype, "origin", void 0);
46
+ tslib_1.__decorate([
47
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The terms it is held under' }),
48
+ tslib_1.__metadata("design:type", String)
49
+ ], MediaItemPatch.prototype, "rightsNote", void 0);
50
+ tslib_1.__decorate([
51
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The last day it may be used, YYYY-MM-DD; empty for none' }),
52
+ tslib_1.__metadata("design:type", String)
53
+ ], MediaItemPatch.prototype, "rightsUntil", void 0);
54
+ tslib_1.__decorate([
55
+ (0, type_graphql_1.Field)(type => media_item_1.MediaPeople, { nullable: true, description: 'Whether people are in it and agreed to be shown' }),
56
+ tslib_1.__metadata("design:type", String)
57
+ ], MediaItemPatch.prototype, "people", void 0);
58
+ tslib_1.__decorate([
59
+ (0, type_graphql_1.Field)(type => [String], { nullable: true, description: "The tags - the attachment's own" }),
60
+ tslib_1.__metadata("design:type", Array)
61
+ ], MediaItemPatch.prototype, "tags", void 0);
62
+ tslib_1.__decorate([
63
+ (0, type_graphql_1.Field)({ nullable: true, description: "The description - the attachment's own" }),
64
+ tslib_1.__metadata("design:type", String)
65
+ ], MediaItemPatch.prototype, "description", void 0);
66
+ exports.MediaItemPatch = MediaItemPatch = tslib_1.__decorate([
67
+ (0, type_graphql_1.InputType)({ description: "A picture's facts to change - only those given change" })
68
+ ], MediaItemPatch);
69
+ let MediaShareFields = class MediaShareFields {
70
+ };
71
+ exports.MediaShareFields = MediaShareFields;
72
+ tslib_1.__decorate([
73
+ (0, type_graphql_1.Field)({ nullable: true, description: 'A caption for the record made of them' }),
74
+ tslib_1.__metadata("design:type", String)
75
+ ], MediaShareFields.prototype, "caption", void 0);
76
+ tslib_1.__decorate([
77
+ (0, type_graphql_1.Field)(type => [String], { nullable: true, description: 'Tags for the record made of them' }),
78
+ tslib_1.__metadata("design:type", Array)
79
+ ], MediaShareFields.prototype, "tags", void 0);
80
+ tslib_1.__decorate([
81
+ (0, type_graphql_1.Field)({ nullable: true, description: 'The event the record hangs on' }),
82
+ tslib_1.__metadata("design:type", String)
83
+ ], MediaShareFields.prototype, "eventId", void 0);
84
+ exports.MediaShareFields = MediaShareFields = tslib_1.__decorate([
85
+ (0, type_graphql_1.InputType)({ description: 'What a person types when sharing pictures to a purpose that makes its own record of them' })
86
+ ], MediaShareFields);
87
+ let MediaShareRoute = class MediaShareRoute {
88
+ };
89
+ exports.MediaShareRoute = MediaShareRoute;
90
+ tslib_1.__decorate([
91
+ (0, type_graphql_1.Field)({ description: 'The purpose shared to' }),
92
+ tslib_1.__metadata("design:type", String)
93
+ ], MediaShareRoute.prototype, "purpose", void 0);
94
+ tslib_1.__decorate([
95
+ (0, type_graphql_1.Field)({ description: "The i18n key of the purpose's name" }),
96
+ tslib_1.__metadata("design:type", String)
97
+ ], MediaShareRoute.prototype, "label", void 0);
98
+ tslib_1.__decorate([
99
+ (0, type_graphql_1.Field)({ description: 'Whether the receiving purpose takes it in first' }),
100
+ tslib_1.__metadata("design:type", Boolean)
101
+ ], MediaShareRoute.prototype, "accept", void 0);
102
+ tslib_1.__decorate([
103
+ (0, type_graphql_1.Field)({ description: 'Whether only the person the picture belongs to shares it' }),
104
+ tslib_1.__metadata("design:type", Boolean)
105
+ ], MediaShareRoute.prototype, "ownerOnly", void 0);
106
+ exports.MediaShareRoute = MediaShareRoute = tslib_1.__decorate([
107
+ (0, type_graphql_1.ObjectType)({ description: 'A purpose pictures of a purpose may be shared to' })
108
+ ], MediaShareRoute);
109
+ let MediaImageQuality = class MediaImageQuality {
110
+ };
111
+ exports.MediaImageQuality = MediaImageQuality;
112
+ tslib_1.__decorate([
113
+ (0, type_graphql_1.Field)({ description: 'low, medium or high' }),
114
+ tslib_1.__metadata("design:type", String)
115
+ ], MediaImageQuality.prototype, "quality", void 0);
116
+ tslib_1.__decorate([
117
+ (0, type_graphql_1.Field)(type => type_graphql_1.Float, { nullable: true, description: 'USD per picture, when the price is known' }),
118
+ tslib_1.__metadata("design:type", Number)
119
+ ], MediaImageQuality.prototype, "price", void 0);
120
+ exports.MediaImageQuality = MediaImageQuality = tslib_1.__decorate([
121
+ (0, type_graphql_1.ObjectType)({ description: 'What one picture costs at a quality step' })
122
+ ], MediaImageQuality);
123
+ let MediaImageModel = class MediaImageModel {
124
+ };
125
+ exports.MediaImageModel = MediaImageModel;
126
+ tslib_1.__decorate([
127
+ (0, type_graphql_1.Field)({ description: 'The agent' }),
128
+ tslib_1.__metadata("design:type", String)
129
+ ], MediaImageModel.prototype, "agentId", void 0);
130
+ tslib_1.__decorate([
131
+ (0, type_graphql_1.Field)({ description: "The agent's name" }),
132
+ tslib_1.__metadata("design:type", String)
133
+ ], MediaImageModel.prototype, "agentName", void 0);
134
+ tslib_1.__decorate([
135
+ (0, type_graphql_1.Field)({ description: 'openai or gemini' }),
136
+ tslib_1.__metadata("design:type", String)
137
+ ], MediaImageModel.prototype, "provider", void 0);
138
+ tslib_1.__decorate([
139
+ (0, type_graphql_1.Field)({ description: 'The image model it makes pictures with' }),
140
+ tslib_1.__metadata("design:type", String)
141
+ ], MediaImageModel.prototype, "model", void 0);
142
+ tslib_1.__decorate([
143
+ (0, type_graphql_1.Field)({ description: 'Whether it is picked first - the default agent when it makes pictures, else the first' }),
144
+ tslib_1.__metadata("design:type", Boolean)
145
+ ], MediaImageModel.prototype, "isDefault", void 0);
146
+ tslib_1.__decorate([
147
+ (0, type_graphql_1.Field)(type => [MediaImageQuality], { description: 'Its quality steps and what a picture costs at each' }),
148
+ tslib_1.__metadata("design:type", Array)
149
+ ], MediaImageModel.prototype, "qualities", void 0);
150
+ exports.MediaImageModel = MediaImageModel = tslib_1.__decorate([
151
+ (0, type_graphql_1.ObjectType)({ description: 'An AI agent of the domain that makes pictures, with its image model' })
152
+ ], MediaImageModel);
153
+ const PICTURE = /^(image|video)\//;
154
+ /** The uploads, each checked to be a picture before anything is stored. */
155
+ async function pictureUploads(files) {
156
+ const out = [];
157
+ for (const file of files ?? []) {
158
+ const upload = await file;
159
+ if (!PICTURE.test(upload?.mimetype ?? ''))
160
+ throw new shell_1.Refusal('media-not-a-picture', { name: upload?.filename ?? '' }, 'only pictures and short videos go in the library');
161
+ out.push({ file, video: upload.mimetype.startsWith('video/') });
162
+ }
163
+ return out;
164
+ }
165
+ async function readableOrRefuse(purpose, targetType, targetId, context) {
166
+ const declared = (0, media_purpose_1.purposeOrRefuse)(purpose);
167
+ if (!(await declared.mayRead({ targetType, targetId }, context)))
168
+ throw new shell_1.Refusal('media-read-denied', {}, 'the record is not one the request may see');
169
+ }
170
+ let MediaFilter = class MediaFilter {
171
+ };
172
+ exports.MediaFilter = MediaFilter;
173
+ tslib_1.__decorate([
174
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Only pictures used for this purpose, or managed by it' }),
175
+ tslib_1.__metadata("design:type", String)
176
+ ], MediaFilter.prototype, "purpose", void 0);
177
+ tslib_1.__decorate([
178
+ (0, type_graphql_1.Field)({ nullable: true, description: 'Words found in the title, the file name, the description or the tags' }),
179
+ tslib_1.__metadata("design:type", String)
180
+ ], MediaFilter.prototype, "text", void 0);
181
+ tslib_1.__decorate([
182
+ (0, type_graphql_1.Field)(type => [String], { nullable: true, description: 'Pictures carrying every one of these tags' }),
183
+ tslib_1.__metadata("design:type", Array)
184
+ ], MediaFilter.prototype, "tags", void 0);
185
+ tslib_1.__decorate([
186
+ (0, type_graphql_1.Field)(type => media_item_1.MediaKind, { nullable: true, description: 'Only this kind of picture' }),
187
+ tslib_1.__metadata("design:type", String)
188
+ ], MediaFilter.prototype, "kind", void 0);
189
+ tslib_1.__decorate([
190
+ (0, type_graphql_1.Field)(type => media_item_1.MediaExposure, { nullable: true, description: 'Only pictures that may be shown at least this far' }),
191
+ tslib_1.__metadata("design:type", String)
192
+ ], MediaFilter.prototype, "exposure", void 0);
193
+ tslib_1.__decorate([
194
+ (0, type_graphql_1.Field)(type => type_graphql_1.Int, { nullable: true, description: 'How many to return, at most 200' }),
195
+ tslib_1.__metadata("design:type", Number)
196
+ ], MediaFilter.prototype, "limit", void 0);
197
+ exports.MediaFilter = MediaFilter = tslib_1.__decorate([
198
+ (0, type_graphql_1.InputType)({ description: 'How the media library is narrowed' })
199
+ ], MediaFilter);
200
+ let MediaItemList = class MediaItemList {
201
+ };
202
+ exports.MediaItemList = MediaItemList;
203
+ tslib_1.__decorate([
204
+ (0, type_graphql_1.Field)(type => [media_item_1.MediaItem], { description: 'The pictures, the latest first' }),
205
+ tslib_1.__metadata("design:type", Array)
206
+ ], MediaItemList.prototype, "items", void 0);
207
+ tslib_1.__decorate([
208
+ (0, type_graphql_1.Field)(type => type_graphql_1.Int, { description: 'How many were returned' }),
209
+ tslib_1.__metadata("design:type", Number)
210
+ ], MediaItemList.prototype, "total", void 0);
211
+ exports.MediaItemList = MediaItemList = tslib_1.__decorate([
212
+ (0, type_graphql_1.ObjectType)({ description: 'Pictures of the media library the request may see' })
213
+ ], MediaItemList);
214
+ const RANK = { INTERNAL: 0, CUSTOMER: 1, PUBLIC: 2 };
215
+ /*
216
+ * 찾기 (ADR-0226 decision 6) - the one door the screens of every purpose and the assistant read. Who sees a picture is
217
+ * judged per picture by the purposes it is used for (media-service mayReadMedia), so the door asks no privilege of its own.
218
+ */
219
+ let MediaResolver = class MediaResolver {
220
+ async mediaItems(filter, context) {
221
+ const { domain } = context.state;
222
+ const limit = Math.min(Math.max(filter?.limit ?? 50, 1), 200);
223
+ const qb = (0, shell_1.getRepository)(media_item_1.MediaItem).createQueryBuilder('M').leftJoinAndSelect('M.attachment', 'A').where('M.domain = :domain', { domain: domain.id });
224
+ if (filter?.purpose) {
225
+ const used = (0, shell_1.getRepository)(media_use_1.MediaUse).createQueryBuilder('U').select('U.item_id').where('U.purpose = :purpose AND U.deleted_at IS NULL');
226
+ qb.andWhere(`(M.home = :purpose OR M.id IN (${used.getQuery()}))`, { purpose: filter.purpose });
227
+ }
228
+ if (filter?.kind)
229
+ qb.andWhere('M.kind = :kind', { kind: filter.kind });
230
+ for (const [n, word] of (filter?.text ?? '').split(/\s+/).filter(Boolean).entries())
231
+ qb.andWhere(`(LOWER(M.title) LIKE :w${n} OR LOWER(A.name) LIKE :w${n} OR LOWER(A.description) LIKE :w${n} OR LOWER(A.tags) LIKE :w${n})`, { [`w${n}`]: `%${word.toLowerCase()}%` });
232
+ const rows = await qb.orderBy('M.createdAt', 'DESC').take(limit * 4).getMany();
233
+ const wanted = (filter?.tags ?? []).map(one => one.replace(/^#/, '').toLowerCase());
234
+ const items = [];
235
+ for (const one of rows) {
236
+ if (items.length >= limit)
237
+ break;
238
+ const tags = (one.attachment?.tags ?? []).map(tag => tag.toLowerCase());
239
+ if (wanted.some(tag => !tags.includes(tag)))
240
+ continue;
241
+ if (filter?.exposure && (RANK[one.exposureConfirmed ? one.exposure : 'INTERNAL'] ?? 0) < (RANK[filter.exposure] ?? 0))
242
+ continue;
243
+ if (await (0, media_service_1.mayReadMedia)(one, context))
244
+ items.push(one);
245
+ }
246
+ return { items, total: items.length };
247
+ }
248
+ async mediaUsedOn(purpose, targetType, targetId, context) {
249
+ await readableOrRefuse(purpose, targetType, targetId, context);
250
+ const used = (await (0, media_service_1.mediaOf)(purpose, targetType, [targetId], context.state.domain.id)).get(targetId) ?? [];
251
+ return used.map(one => ({ ...one.item, attachment: one.attachment }));
252
+ }
253
+ async mediaShareRoutes(purpose) {
254
+ return (0, media_service_1.mediaShareRoutesOf)(purpose);
255
+ }
256
+ async uploadMediaItems(purpose, files, targetType, targetId, context) {
257
+ const declared = (0, media_purpose_1.purposeOrRefuse)(purpose);
258
+ if (!declared.mayAdd || !(await declared.mayAdd(context)))
259
+ throw new shell_1.Refusal('media-add-denied', {}, 'pictures are not added here');
260
+ if (!!targetType !== !!targetId)
261
+ throw new shell_1.Refusal('media-target-incomplete', {}, 'a record is named by its kind and its id');
262
+ if (targetType)
263
+ await readableOrRefuse(purpose, targetType, targetId, context);
264
+ const uploads = await pictureUploads(files);
265
+ if (!uploads.length)
266
+ throw new shell_1.Refusal('media-no-file', {}, 'choose at least one picture');
267
+ const added = [];
268
+ const before = targetType ? ((await (0, media_service_1.mediaOf)(purpose, targetType, [targetId], context.state.domain.id, context.state.tx)).get(targetId) ?? []) : [];
269
+ const from = before.reduce((most, one) => Math.max(most, one.use.rank), -1) + 1;
270
+ for (const [n, { file, video }] of uploads.entries()) {
271
+ const item = await (0, media_service_1.addMedia)({ file, home: purpose, kind: video ? media_item_1.MediaKind.VIDEO : media_item_1.MediaKind.PHOTO }, context);
272
+ if (targetType)
273
+ await (0, media_service_1.useMedia)({ itemId: item.id, purpose, targetType, targetId: targetId, rank: from + n }, context);
274
+ added.push(item);
275
+ }
276
+ return added;
277
+ }
278
+ async updateMediaItem(id, patch, context) {
279
+ return await (0, media_service_1.updateMediaFacts)(id, patch, context);
280
+ }
281
+ async deleteMediaItems(ids, context) {
282
+ return await (0, media_service_1.deleteMediaItems)(ids, context);
283
+ }
284
+ async unuseMediaItems(ids, purpose, targetType, targetId, context) {
285
+ await readableOrRefuse(purpose, targetType, targetId, context);
286
+ const declared = (0, media_purpose_1.purposeOrRefuse)(purpose);
287
+ const items = await (0, shell_1.getRepository)(media_item_1.MediaItem, context.state.tx).find({ where: { id: (0, typeorm_1.In)(ids), domain: { id: context.state.domain.id } } });
288
+ for (const item of items)
289
+ if (!(await declared.mayManage(item, context)))
290
+ throw new shell_1.Refusal('media-manage-denied', {}, 'only the people who manage the picture change or delete it');
291
+ await (0, media_service_1.unuseMedia)({ purpose, targetType, targetId, itemIds: items.map(one => one.id) }, context);
292
+ return true;
293
+ }
294
+ async shareMediaItems(ids, to, input, context) {
295
+ return await (0, media_service_1.shareMedia)(ids, to, input ?? {}, context);
296
+ }
297
+ async acceptMediaItems(ids, purpose, context) {
298
+ return await (0, media_service_1.acceptMedia)(ids, purpose, context);
299
+ }
300
+ async declineMediaItems(ids, purpose, context) {
301
+ return await (0, media_service_1.declineMedia)(ids, purpose, context);
302
+ }
303
+ async mediaImageModels(purpose, context) {
304
+ return await (0, media_ai_1.imageAgentsFor)(purpose, context);
305
+ }
306
+ async createMediaByAi(purpose, prompt, agentId, quality, size, targetType, targetId, context) {
307
+ return await (0, media_ai_1.createMediaByAi)({ purpose, prompt, agentId, quality, size, targetType, targetId }, context);
308
+ }
309
+ async useCount(item) {
310
+ const uses = await (0, shell_1.getRepository)(media_use_1.MediaUse).find({ where: { item: { id: item.id } } });
311
+ return uses.filter(one => one.targetType !== media_purpose_1.MEDIA_INBOX).length;
312
+ }
313
+ async awaiting(item) {
314
+ const uses = await (0, shell_1.getRepository)(media_use_1.MediaUse).find({ where: { item: { id: item.id }, targetType: media_purpose_1.MEDIA_INBOX } });
315
+ return [...new Set(uses.map(one => one.purpose))];
316
+ }
317
+ async mayManage(item, context) {
318
+ return await (0, media_service_1.mayManageMedia)(item, context);
319
+ }
320
+ async description(item) {
321
+ return (await fileOf(item))?.description ?? undefined;
322
+ }
323
+ madeByAi(item) {
324
+ return item.origin === media_item_1.MediaOrigin.AI;
325
+ }
326
+ async mimetype(item) {
327
+ return (await fileOf(item))?.mimetype ?? undefined;
328
+ }
329
+ async name(item) {
330
+ return (await fileOf(item))?.name;
331
+ }
332
+ async fullpath(item) {
333
+ return (await fileOf(item))?.fullpath;
334
+ }
335
+ async thumbnail(item) {
336
+ return (await fileOf(item))?.thumbnail ?? undefined;
337
+ }
338
+ async tags(item) {
339
+ return (await fileOf(item))?.tags ?? [];
340
+ }
341
+ async purposes(item) {
342
+ const uses = await (0, shell_1.getRepository)(media_use_1.MediaUse).find({ where: { item: { id: item.id } } });
343
+ return [...new Set(uses.filter(one => one.targetType !== media_purpose_1.MEDIA_INBOX).map(one => one.purpose))];
344
+ }
345
+ };
346
+ exports.MediaResolver = MediaResolver;
347
+ tslib_1.__decorate([
348
+ (0, type_graphql_1.Query)(returns => MediaItemList, { description: 'Pictures of the media library the request may see, narrowed by purpose, words, tags, kind and exposure' }),
349
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('filter', type => MediaFilter, { nullable: true })),
350
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
351
+ tslib_1.__metadata("design:type", Function),
352
+ tslib_1.__metadata("design:paramtypes", [MediaFilter, Object]),
353
+ tslib_1.__metadata("design:returntype", Promise)
354
+ ], MediaResolver.prototype, "mediaItems", null);
355
+ tslib_1.__decorate([
356
+ (0, type_graphql_1.Query)(returns => [media_item_1.MediaItem], { description: 'The pictures on one record of a purpose, in their order - for whoever may see the record' }),
357
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('purpose')),
358
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('targetType')),
359
+ tslib_1.__param(2, (0, type_graphql_1.Arg)('targetId')),
360
+ tslib_1.__param(3, (0, type_graphql_1.Ctx)()),
361
+ tslib_1.__metadata("design:type", Function),
362
+ tslib_1.__metadata("design:paramtypes", [String, String, String, Object]),
363
+ tslib_1.__metadata("design:returntype", Promise)
364
+ ], MediaResolver.prototype, "mediaUsedOn", null);
365
+ tslib_1.__decorate([
366
+ (0, type_graphql_1.Query)(returns => [MediaShareRoute], { description: 'Where pictures of a purpose may be shared - to purposes some module declared' }),
367
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('purpose')),
368
+ tslib_1.__metadata("design:type", Function),
369
+ tslib_1.__metadata("design:paramtypes", [String]),
370
+ tslib_1.__metadata("design:returntype", Promise)
371
+ ], MediaResolver.prototype, "mediaShareRoutes", null);
372
+ tslib_1.__decorate([
373
+ (0, type_graphql_1.Directive)('@transaction'),
374
+ (0, type_graphql_1.Mutation)(returns => [media_item_1.MediaItem], { description: 'Adds pictures under a purpose that lets the request add them, and puts them on its record when one is named' }),
375
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('purpose')),
376
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('files', type => [GraphQLUpload_js_1.default])),
377
+ tslib_1.__param(2, (0, type_graphql_1.Arg)('targetType', { nullable: true })),
378
+ tslib_1.__param(3, (0, type_graphql_1.Arg)('targetId', { nullable: true })),
379
+ tslib_1.__param(4, (0, type_graphql_1.Ctx)()),
380
+ tslib_1.__metadata("design:type", Function),
381
+ tslib_1.__metadata("design:paramtypes", [String, Array, String, String, Object]),
382
+ tslib_1.__metadata("design:returntype", Promise)
383
+ ], MediaResolver.prototype, "uploadMediaItems", null);
384
+ tslib_1.__decorate([
385
+ (0, type_graphql_1.Directive)('@transaction'),
386
+ (0, type_graphql_1.Mutation)(returns => media_item_1.MediaItem, { description: "Changes a picture's facts - by the people who manage it" }),
387
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
388
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('patch', type => MediaItemPatch)),
389
+ tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
390
+ tslib_1.__metadata("design:type", Function),
391
+ tslib_1.__metadata("design:paramtypes", [String, MediaItemPatch, Object]),
392
+ tslib_1.__metadata("design:returntype", Promise)
393
+ ], MediaResolver.prototype, "updateMediaItem", null);
394
+ tslib_1.__decorate([
395
+ (0, type_graphql_1.Directive)('@transaction'),
396
+ (0, type_graphql_1.Mutation)(returns => type_graphql_1.Int, { description: 'Deletes pictures used nowhere - by the people who manage them' }),
397
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('ids', type => [String])),
398
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
399
+ tslib_1.__metadata("design:type", Function),
400
+ tslib_1.__metadata("design:paramtypes", [Array, Object]),
401
+ tslib_1.__metadata("design:returntype", Promise)
402
+ ], MediaResolver.prototype, "deleteMediaItems", null);
403
+ tslib_1.__decorate([
404
+ (0, type_graphql_1.Directive)('@transaction'),
405
+ (0, type_graphql_1.Mutation)(returns => Boolean, { description: 'Takes pictures off one record of a purpose - the record must be one the request may see and the pictures its to manage' }),
406
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('ids', type => [String])),
407
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('purpose')),
408
+ tslib_1.__param(2, (0, type_graphql_1.Arg)('targetType')),
409
+ tslib_1.__param(3, (0, type_graphql_1.Arg)('targetId')),
410
+ tslib_1.__param(4, (0, type_graphql_1.Ctx)()),
411
+ tslib_1.__metadata("design:type", Function),
412
+ tslib_1.__metadata("design:paramtypes", [Array, String, String, String, Object]),
413
+ tslib_1.__metadata("design:returntype", Promise)
414
+ ], MediaResolver.prototype, "unuseMediaItems", null);
415
+ tslib_1.__decorate([
416
+ (0, type_graphql_1.Directive)('@transaction'),
417
+ (0, type_graphql_1.Mutation)(returns => type_graphql_1.Int, { description: 'Shares pictures to another purpose on a route their purpose declares - no file is copied' }),
418
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('ids', type => [String])),
419
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('to')),
420
+ tslib_1.__param(2, (0, type_graphql_1.Arg)('input', type => MediaShareFields, { nullable: true })),
421
+ tslib_1.__param(3, (0, type_graphql_1.Ctx)()),
422
+ tslib_1.__metadata("design:type", Function),
423
+ tslib_1.__metadata("design:paramtypes", [Array, String, MediaShareFields, Object]),
424
+ tslib_1.__metadata("design:returntype", Promise)
425
+ ], MediaResolver.prototype, "shareMediaItems", null);
426
+ tslib_1.__decorate([
427
+ (0, type_graphql_1.Directive)('@transaction'),
428
+ (0, type_graphql_1.Mutation)(returns => type_graphql_1.Int, { description: "Takes in pictures waiting in a purpose's inbox - the purpose manages them from now on" }),
429
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('ids', type => [String])),
430
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('purpose')),
431
+ tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
432
+ tslib_1.__metadata("design:type", Function),
433
+ tslib_1.__metadata("design:paramtypes", [Array, String, Object]),
434
+ tslib_1.__metadata("design:returntype", Promise)
435
+ ], MediaResolver.prototype, "acceptMediaItems", null);
436
+ tslib_1.__decorate([
437
+ (0, type_graphql_1.Directive)('@transaction'),
438
+ (0, type_graphql_1.Mutation)(returns => type_graphql_1.Int, { description: "Sends back pictures waiting in a purpose's inbox - they stay where they came from" }),
439
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('ids', type => [String])),
440
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('purpose')),
441
+ tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
442
+ tslib_1.__metadata("design:type", Function),
443
+ tslib_1.__metadata("design:paramtypes", [Array, String, Object]),
444
+ tslib_1.__metadata("design:returntype", Promise)
445
+ ], MediaResolver.prototype, "declineMediaItems", null);
446
+ tslib_1.__decorate([
447
+ (0, type_graphql_1.Query)(returns => [MediaImageModel], { description: 'The AI agents the request may make pictures of a purpose with - none where the purpose makes no AI pictures' }),
448
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('purpose')),
449
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
450
+ tslib_1.__metadata("design:type", Function),
451
+ tslib_1.__metadata("design:paramtypes", [String, Object]),
452
+ tslib_1.__metadata("design:returntype", Promise)
453
+ ], MediaResolver.prototype, "mediaImageModels", null);
454
+ tslib_1.__decorate([
455
+ (0, type_graphql_1.Directive)('@transaction'),
456
+ (0, type_graphql_1.Mutation)(returns => media_item_1.MediaItem, { description: 'Makes a picture by AI under a purpose that allows it, and puts it on its record when one is named' }),
457
+ tslib_1.__param(0, (0, type_graphql_1.Arg)('purpose')),
458
+ tslib_1.__param(1, (0, type_graphql_1.Arg)('prompt')),
459
+ tslib_1.__param(2, (0, type_graphql_1.Arg)('agentId', { nullable: true })),
460
+ tslib_1.__param(3, (0, type_graphql_1.Arg)('quality', { nullable: true })),
461
+ tslib_1.__param(4, (0, type_graphql_1.Arg)('size', { nullable: true })),
462
+ tslib_1.__param(5, (0, type_graphql_1.Arg)('targetType', { nullable: true })),
463
+ tslib_1.__param(6, (0, type_graphql_1.Arg)('targetId', { nullable: true })),
464
+ tslib_1.__param(7, (0, type_graphql_1.Ctx)()),
465
+ tslib_1.__metadata("design:type", Function),
466
+ tslib_1.__metadata("design:paramtypes", [String, String, String, String, String, String, String, Object]),
467
+ tslib_1.__metadata("design:returntype", Promise)
468
+ ], MediaResolver.prototype, "createMediaByAi", null);
469
+ tslib_1.__decorate([
470
+ (0, type_graphql_1.FieldResolver)(type => type_graphql_1.Int, { description: 'How many records it is used on - an inbox is not one' }),
471
+ tslib_1.__param(0, (0, type_graphql_1.Root)()),
472
+ tslib_1.__metadata("design:type", Function),
473
+ tslib_1.__metadata("design:paramtypes", [media_item_1.MediaItem]),
474
+ tslib_1.__metadata("design:returntype", Promise)
475
+ ], MediaResolver.prototype, "useCount", null);
476
+ tslib_1.__decorate([
477
+ (0, type_graphql_1.FieldResolver)(type => [String], { description: 'The purposes whose inbox it waits in' }),
478
+ tslib_1.__param(0, (0, type_graphql_1.Root)()),
479
+ tslib_1.__metadata("design:type", Function),
480
+ tslib_1.__metadata("design:paramtypes", [media_item_1.MediaItem]),
481
+ tslib_1.__metadata("design:returntype", Promise)
482
+ ], MediaResolver.prototype, "awaiting", null);
483
+ tslib_1.__decorate([
484
+ (0, type_graphql_1.FieldResolver)(type => Boolean, { description: 'Whether the request manages it - changes its facts and deletes it' }),
485
+ tslib_1.__param(0, (0, type_graphql_1.Root)()),
486
+ tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
487
+ tslib_1.__metadata("design:type", Function),
488
+ tslib_1.__metadata("design:paramtypes", [media_item_1.MediaItem, Object]),
489
+ tslib_1.__metadata("design:returntype", Promise)
490
+ ], MediaResolver.prototype, "mayManage", null);
491
+ tslib_1.__decorate([
492
+ (0, type_graphql_1.FieldResolver)(type => String, { nullable: true, description: "The description - the attachment's own" }),
493
+ tslib_1.__param(0, (0, type_graphql_1.Root)()),
494
+ tslib_1.__metadata("design:type", Function),
495
+ tslib_1.__metadata("design:paramtypes", [media_item_1.MediaItem]),
496
+ tslib_1.__metadata("design:returntype", Promise)
497
+ ], MediaResolver.prototype, "description", null);
498
+ tslib_1.__decorate([
499
+ (0, type_graphql_1.FieldResolver)(type => Boolean, { description: 'Whether it was made by AI - said beside it wherever it is shown' }),
500
+ tslib_1.__param(0, (0, type_graphql_1.Root)()),
501
+ tslib_1.__metadata("design:type", Function),
502
+ tslib_1.__metadata("design:paramtypes", [media_item_1.MediaItem]),
503
+ tslib_1.__metadata("design:returntype", Boolean)
504
+ ], MediaResolver.prototype, "madeByAi", null);
505
+ tslib_1.__decorate([
506
+ (0, type_graphql_1.FieldResolver)(type => String, { nullable: true, description: 'The file type' }),
507
+ tslib_1.__param(0, (0, type_graphql_1.Root)()),
508
+ tslib_1.__metadata("design:type", Function),
509
+ tslib_1.__metadata("design:paramtypes", [media_item_1.MediaItem]),
510
+ tslib_1.__metadata("design:returntype", Promise)
511
+ ], MediaResolver.prototype, "mimetype", null);
512
+ tslib_1.__decorate([
513
+ (0, type_graphql_1.FieldResolver)(type => String, { nullable: true, description: 'The file name' }),
514
+ tslib_1.__param(0, (0, type_graphql_1.Root)()),
515
+ tslib_1.__metadata("design:type", Function),
516
+ tslib_1.__metadata("design:paramtypes", [media_item_1.MediaItem]),
517
+ tslib_1.__metadata("design:returntype", Promise)
518
+ ], MediaResolver.prototype, "name", null);
519
+ tslib_1.__decorate([
520
+ (0, type_graphql_1.FieldResolver)(type => String, { nullable: true, description: 'Where the picture itself is read' }),
521
+ tslib_1.__param(0, (0, type_graphql_1.Root)()),
522
+ tslib_1.__metadata("design:type", Function),
523
+ tslib_1.__metadata("design:paramtypes", [media_item_1.MediaItem]),
524
+ tslib_1.__metadata("design:returntype", Promise)
525
+ ], MediaResolver.prototype, "fullpath", null);
526
+ tslib_1.__decorate([
527
+ (0, type_graphql_1.FieldResolver)(type => String, { nullable: true, description: 'A small picture of it, usable as an image source' }),
528
+ tslib_1.__param(0, (0, type_graphql_1.Root)()),
529
+ tslib_1.__metadata("design:type", Function),
530
+ tslib_1.__metadata("design:paramtypes", [media_item_1.MediaItem]),
531
+ tslib_1.__metadata("design:returntype", Promise)
532
+ ], MediaResolver.prototype, "thumbnail", null);
533
+ tslib_1.__decorate([
534
+ (0, type_graphql_1.FieldResolver)(type => [String], { description: "The tags - the attachment's own" }),
535
+ tslib_1.__param(0, (0, type_graphql_1.Root)()),
536
+ tslib_1.__metadata("design:type", Function),
537
+ tslib_1.__metadata("design:paramtypes", [media_item_1.MediaItem]),
538
+ tslib_1.__metadata("design:returntype", Promise)
539
+ ], MediaResolver.prototype, "tags", null);
540
+ tslib_1.__decorate([
541
+ (0, type_graphql_1.FieldResolver)(type => [String], { description: 'The purposes it is used for' }),
542
+ tslib_1.__param(0, (0, type_graphql_1.Root)()),
543
+ tslib_1.__metadata("design:type", Function),
544
+ tslib_1.__metadata("design:paramtypes", [media_item_1.MediaItem]),
545
+ tslib_1.__metadata("design:returntype", Promise)
546
+ ], MediaResolver.prototype, "purposes", null);
547
+ exports.MediaResolver = MediaResolver = tslib_1.__decorate([
548
+ (0, type_graphql_1.UseMiddleware)(shell_1.SpeakRefusals),
549
+ (0, type_graphql_1.Resolver)(media_item_1.MediaItem)
550
+ ], MediaResolver);
551
+ async function fileOf(item) {
552
+ if (item.attachment)
553
+ return item.attachment;
554
+ if (!item.attachmentId)
555
+ return undefined;
556
+ return (await (0, shell_1.getRepository)(attachment_base_1.Attachment).find({ where: { id: (0, typeorm_1.In)([item.attachmentId]) } }))[0];
557
+ }
558
+ //# sourceMappingURL=media-resolver.js.map
@@ -0,0 +1,107 @@
1
+ import { EntityManager } from 'typeorm';
2
+ import { Attachment } from '@things-factory/attachment-base';
3
+ import { MediaExposure, MediaItem, MediaKind, MediaOrigin, MediaPeople } from './media-item';
4
+ import { MediaShareInput } from './media-purpose';
5
+ import { MediaUse } from './media-use';
6
+ /** The attachment of a picture hangs on its item under this refType (attachment-base). */
7
+ export declare const MEDIA_REF_TYPE = "Media Item";
8
+ export interface NewMedia {
9
+ file: any;
10
+ /** The purpose that manages it - its writers change its facts and delete it. */
11
+ home: string;
12
+ title?: string | null;
13
+ kind?: MediaKind;
14
+ takenAt?: Date | null;
15
+ place?: string | null;
16
+ /** The person it belongs to, when it is a person's own. */
17
+ ownerId?: string | null;
18
+ exposure?: MediaExposure;
19
+ people?: MediaPeople;
20
+ origin?: MediaOrigin;
21
+ /** How it was made, when made by AI (decision 8). */
22
+ generation?: MediaItem['generation'] | null;
23
+ /** The attachment's own tags and description - the library keeps no second copy. */
24
+ tags?: string[] | null;
25
+ description?: string | null;
26
+ }
27
+ /** Tags as the attachment keeps them - trimmed, without the # mark, each once. */
28
+ export declare function tagsOfMedia(tags?: string[] | null): string[] | null;
29
+ /** Adds a picture: the item, then its file as an attachment of the item. */
30
+ export declare function addMedia(input: NewMedia, context: any): Promise<MediaItem>;
31
+ export interface UseOfMedia {
32
+ itemId: string;
33
+ purpose: string;
34
+ targetType: string;
35
+ targetId: string;
36
+ targetExposure?: MediaExposure;
37
+ rank?: number;
38
+ }
39
+ /** Puts a picture on a record - refused when the picture may not be shown there (decision 4). */
40
+ export declare function useMedia(use: UseOfMedia, context: any, today?: string): Promise<MediaUse>;
41
+ /**
42
+ * Takes pictures off a record - all of them, or the items named. A picture left with no use that the purpose itself
43
+ * manages goes with its file: taking the last photo off a post deletes it, as the post's photo was deleted before. A
44
+ * picture another purpose manages, still used elsewhere, or of a purpose that keeps unused pictures, stays.
45
+ */
46
+ export declare function unuseMedia(target: {
47
+ purpose: string;
48
+ targetType: string;
49
+ targetId: string;
50
+ itemIds?: string[];
51
+ }, context: any): Promise<void>;
52
+ /** Deletes a picture and its file - refused while it is used anywhere (decision 4). */
53
+ export declare function deleteMediaItem(item: MediaItem, context: any): Promise<void>;
54
+ export interface UsedMedia {
55
+ use: MediaUse;
56
+ item: MediaItem;
57
+ attachment: Attachment;
58
+ }
59
+ /** The pictures on each record of a purpose, in their order. */
60
+ export declare function mediaOf(purpose: string, targetType: string, targetIds: string[], domainId: string, tx?: EntityManager): Promise<Map<string, UsedMedia[]>>;
61
+ /**
62
+ * Decision 5-1 - who sees a picture: whoever may read one of the records it is used on, the person it belongs to, and
63
+ * whoever manages it. A picture used nowhere yet is seen by its home's managers and by whoever added it.
64
+ */
65
+ export declare function mayReadMedia(item: MediaItem, context: any): Promise<boolean>;
66
+ /** The items of the request's domain, in the order asked - refused when one is gone. */
67
+ export declare function itemsOrRefuse(ids: string[], context: any): Promise<MediaItem[]>;
68
+ /** Whether the request manages the item - its home's writers (decision 5). */
69
+ export declare function mayManageMedia(item: MediaItem, context: any): Promise<boolean>;
70
+ export interface MediaFacts {
71
+ title?: string | null;
72
+ kind?: MediaKind | null;
73
+ takenAt?: Date | null;
74
+ place?: string | null;
75
+ exposure?: MediaExposure | null;
76
+ exposureConfirmed?: boolean | null;
77
+ origin?: MediaOrigin | null;
78
+ rightsNote?: string | null;
79
+ rightsUntil?: string | null;
80
+ people?: MediaPeople | null;
81
+ tags?: string[] | null;
82
+ description?: string | null;
83
+ }
84
+ /**
85
+ * Changes a picture's facts - by its home's writers only. The tags and the description are the attachment's. A picture
86
+ * may not come to be shown less far than a record it is used on (decision 4).
87
+ */
88
+ export declare function updateMediaFacts(itemId: string, facts: MediaFacts, context: any): Promise<MediaItem>;
89
+ /** Deletes pictures - by their home's writers, and only those used nowhere (decision 4). */
90
+ export declare function deleteMediaItems(ids: string[], context: any): Promise<number>;
91
+ /**
92
+ * Decision 5-2 - shares pictures to another purpose. Each must be managed by the request and its home must declare the
93
+ * route. A route with `accept` puts the picture in the receiving purpose's inbox; otherwise the receiving purpose
94
+ * takes it in itself (`receive` - the gallery makes a post). No file is copied.
95
+ */
96
+ export declare function shareMedia(itemIds: string[], to: string, input: MediaShareInput, context: any): Promise<number>;
97
+ /** Takes in pictures waiting in the purpose's inbox: the purpose becomes their home (decision 5-2, Q3). */
98
+ export declare function acceptMedia(itemIds: string[], purpose: string, context: any): Promise<number>;
99
+ /** Sends back pictures waiting in the purpose's inbox - they stay where they came from, as they were. */
100
+ export declare function declineMedia(itemIds: string[], purpose: string, context: any): Promise<number>;
101
+ /** The routes a picture of `purpose` may be shared on, to purposes some module declared. */
102
+ export declare function mediaShareRoutesOf(purpose: string): {
103
+ purpose: string;
104
+ label: string;
105
+ accept: boolean;
106
+ ownerOnly: boolean;
107
+ }[];