@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,325 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MEDIA_REF_TYPE = void 0;
4
+ exports.tagsOfMedia = tagsOfMedia;
5
+ exports.addMedia = addMedia;
6
+ exports.useMedia = useMedia;
7
+ exports.unuseMedia = unuseMedia;
8
+ exports.deleteMediaItem = deleteMediaItem;
9
+ exports.mediaOf = mediaOf;
10
+ exports.mayReadMedia = mayReadMedia;
11
+ exports.itemsOrRefuse = itemsOrRefuse;
12
+ exports.mayManageMedia = mayManageMedia;
13
+ exports.updateMediaFacts = updateMediaFacts;
14
+ exports.deleteMediaItems = deleteMediaItems;
15
+ exports.shareMedia = shareMedia;
16
+ exports.acceptMedia = acceptMedia;
17
+ exports.declineMedia = declineMedia;
18
+ exports.mediaShareRoutesOf = mediaShareRoutesOf;
19
+ const typeorm_1 = require("typeorm");
20
+ const attachment_base_1 = require("@things-factory/attachment-base");
21
+ const shell_1 = require("@things-factory/shell");
22
+ const media_item_1 = require("./media-item");
23
+ const media_purpose_1 = require("./media-purpose");
24
+ const media_use_1 = require("./media-use");
25
+ /*
26
+ * What the library does with the database (ADR-0226): add a picture under the purpose that manages it, put it on a
27
+ * record, take it off, read the pictures of records, and say who sees a picture. Modules call these in their own
28
+ * transaction; the attachment under a picture is attachment-base's as ever.
29
+ */
30
+ /** The attachment of a picture hangs on its item under this refType (attachment-base). */
31
+ exports.MEDIA_REF_TYPE = 'Media Item';
32
+ const dayOf = (date) => date.toISOString().slice(0, 10);
33
+ /** Tags as the attachment keeps them - trimmed, without the # mark, each once. */
34
+ function tagsOfMedia(tags) {
35
+ const out = [...new Set((tags ?? []).map(one => String(one).trim().replace(/^#/, '')).filter(Boolean))];
36
+ return out.length ? out : null;
37
+ }
38
+ /** Adds a picture: the item, then its file as an attachment of the item. */
39
+ async function addMedia(input, context) {
40
+ const { domain, user, tx } = context.state;
41
+ (0, media_purpose_1.purposeOrRefuse)(input.home);
42
+ const repository = (0, shell_1.getRepository)(media_item_1.MediaItem, tx);
43
+ const item = await repository.save({
44
+ domain,
45
+ home: input.home,
46
+ title: input.title?.trim() || null,
47
+ kind: input.kind ?? media_item_1.MediaKind.PHOTO,
48
+ takenAt: input.takenAt ?? null,
49
+ place: input.place?.trim() || null,
50
+ owner: input.ownerId ? { id: input.ownerId } : null,
51
+ exposure: input.exposure ?? media_item_1.MediaExposure.INTERNAL,
52
+ exposureConfirmed: false,
53
+ people: input.people ?? media_item_1.MediaPeople.NOT_ASKED,
54
+ origin: input.origin ?? media_item_1.MediaOrigin.OWN,
55
+ generation: input.generation ?? null,
56
+ creator: user,
57
+ updater: user
58
+ });
59
+ const attachment = await (0, attachment_base_1.createAttachment)(null, { attachment: { file: input.file, refType: exports.MEDIA_REF_TYPE, refBy: item.id } }, context);
60
+ await repository.update(item.id, { attachment: { id: attachment.id } });
61
+ const tags = tagsOfMedia(input.tags);
62
+ if (tags || input.description?.trim())
63
+ await (0, shell_1.getRepository)(attachment_base_1.Attachment, tx).update(attachment.id, { ...(tags ? { tags } : {}), ...(input.description?.trim() ? { description: input.description.trim() } : {}) });
64
+ return (await repository.findOneBy({ id: item.id }));
65
+ }
66
+ /** Puts a picture on a record - refused when the picture may not be shown there (decision 4). */
67
+ async function useMedia(use, context, today = dayOf(new Date())) {
68
+ const { domain, user, tx } = context.state;
69
+ const purpose = (0, media_purpose_1.purposeOrRefuse)(use.purpose);
70
+ const item = await (0, shell_1.getRepository)(media_item_1.MediaItem, tx).findOne({ where: { id: use.itemId, domain: { id: domain.id } } });
71
+ if (!item)
72
+ throw new shell_1.Refusal('media-item-missing', {}, 'the picture is not in the library any more');
73
+ const targetExposure = use.targetExposure ?? media_item_1.MediaExposure.INTERNAL;
74
+ const refusal = (0, media_purpose_1.useRefusal)(item, purpose, targetExposure, today);
75
+ if (refusal)
76
+ throw refusal;
77
+ const repository = (0, shell_1.getRepository)(media_use_1.MediaUse, tx);
78
+ const where = { domain: { id: domain.id }, item: { id: item.id }, purpose: use.purpose, targetType: use.targetType, targetId: use.targetId };
79
+ const before = await repository.findOne({ where });
80
+ return await repository.save({
81
+ ...(before ?? { domain, item: { id: item.id }, purpose: use.purpose, targetType: use.targetType, targetId: use.targetId, creator: user }),
82
+ targetExposure,
83
+ rank: use.rank ?? before?.rank ?? 0,
84
+ updater: user
85
+ });
86
+ }
87
+ /**
88
+ * Takes pictures off a record - all of them, or the items named. A picture left with no use that the purpose itself
89
+ * manages goes with its file: taking the last photo off a post deletes it, as the post's photo was deleted before. A
90
+ * picture another purpose manages, still used elsewhere, or of a purpose that keeps unused pictures, stays.
91
+ */
92
+ async function unuseMedia(target, context) {
93
+ const { domain, tx } = context.state;
94
+ const uses = (0, shell_1.getRepository)(media_use_1.MediaUse, tx);
95
+ const rows = await uses.find({
96
+ where: {
97
+ domain: { id: domain.id },
98
+ purpose: target.purpose,
99
+ targetType: target.targetType,
100
+ targetId: target.targetId,
101
+ ...(target.itemIds ? { item: { id: (0, typeorm_1.In)(target.itemIds) } } : {})
102
+ }
103
+ });
104
+ if (!rows.length)
105
+ return;
106
+ await uses.softRemove(rows);
107
+ const itemIds = [...new Set(rows.map(one => one.itemId))];
108
+ const stillUsed = new Set((await uses.find({ where: { item: { id: (0, typeorm_1.In)(itemIds) } } })).map(one => one.itemId));
109
+ if ((0, media_purpose_1.mediaPurposeOf)(target.purpose)?.keepUnused)
110
+ return;
111
+ const orphans = await (0, shell_1.getRepository)(media_item_1.MediaItem, tx).find({ where: { id: (0, typeorm_1.In)(itemIds.filter(id => !stillUsed.has(id))), home: target.purpose } });
112
+ for (const item of orphans)
113
+ await deleteMediaItem(item, context);
114
+ }
115
+ /** Deletes a picture and its file - refused while it is used anywhere (decision 4). */
116
+ async function deleteMediaItem(item, context) {
117
+ const { tx } = context.state;
118
+ const used = await (0, shell_1.getRepository)(media_use_1.MediaUse, tx).count({ where: { item: { id: item.id } } });
119
+ if (used)
120
+ throw new shell_1.Refusal('media-item-in-use', { count: used }, `the picture is used in ${used} places - take it off them first`);
121
+ const attachmentId = item.attachmentId;
122
+ /* The item lets go of its file first - the file row is removed, the item is kept as deleted. */
123
+ await (0, shell_1.getRepository)(media_item_1.MediaItem, tx).update(item.id, { attachment: null });
124
+ await (0, shell_1.getRepository)(media_item_1.MediaItem, tx).softDelete(item.id);
125
+ if (attachmentId)
126
+ await (0, attachment_base_1.deleteAttachment)(null, { id: attachmentId }, context);
127
+ }
128
+ /** The pictures on each record of a purpose, in their order. */
129
+ async function mediaOf(purpose, targetType, targetIds, domainId, tx) {
130
+ const out = new Map();
131
+ if (!targetIds.length)
132
+ return out;
133
+ const uses = await (0, shell_1.getRepository)(media_use_1.MediaUse, tx).find({
134
+ where: { domain: { id: domainId }, purpose, targetType, targetId: (0, typeorm_1.In)(targetIds) },
135
+ order: { rank: 'ASC', createdAt: 'ASC' }
136
+ });
137
+ if (!uses.length)
138
+ return out;
139
+ const items = new Map((await (0, shell_1.getRepository)(media_item_1.MediaItem, tx).find({ where: { id: (0, typeorm_1.In)([...new Set(uses.map(one => one.itemId))]) } })).map(one => [one.id, one]));
140
+ const attachmentIds = [...items.values()].map(one => one.attachmentId).filter(Boolean);
141
+ const files = new Map((attachmentIds.length ? await (0, shell_1.getRepository)(attachment_base_1.Attachment, tx).find({ where: { id: (0, typeorm_1.In)(attachmentIds) } }) : []).map(one => [one.id, one]));
142
+ for (const use of uses) {
143
+ const item = items.get(use.itemId);
144
+ const attachment = item?.attachmentId ? files.get(item.attachmentId) : undefined;
145
+ if (!item || !attachment)
146
+ continue;
147
+ out.set(use.targetId, [...(out.get(use.targetId) ?? []), { use, item, attachment }]);
148
+ }
149
+ return out;
150
+ }
151
+ /**
152
+ * Decision 5-1 - who sees a picture: whoever may read one of the records it is used on, the person it belongs to, and
153
+ * whoever manages it. A picture used nowhere yet is seen by its home's managers and by whoever added it.
154
+ */
155
+ async function mayReadMedia(item, context) {
156
+ const { domain, user, tx } = context?.state ?? {};
157
+ if (!domain || !user || item.domainId !== domain.id)
158
+ return false;
159
+ if (item.ownerId === user.id || item.creatorId === user.id)
160
+ return true;
161
+ const uses = await (0, shell_1.getRepository)(media_use_1.MediaUse, tx).find({ where: { item: { id: item.id } } });
162
+ for (const use of uses) {
163
+ const purpose = (0, media_purpose_1.mediaPurposeOf)(use.purpose);
164
+ if (purpose && (await purpose.mayRead({ targetType: use.targetType, targetId: use.targetId }, context)))
165
+ return true;
166
+ }
167
+ const home = (0, media_purpose_1.mediaPurposeOf)(item.home);
168
+ return !!home && (await home.mayManage(item, context));
169
+ }
170
+ /* ------------------------------------------------------------------ stage 2: the doors' work (ADR-0226 decision 5) */
171
+ /** The items of the request's domain, in the order asked - refused when one is gone. */
172
+ async function itemsOrRefuse(ids, context) {
173
+ const { domain, tx } = context.state;
174
+ const wanted = [...new Set(ids ?? [])];
175
+ if (!wanted.length)
176
+ return [];
177
+ const rows = await (0, shell_1.getRepository)(media_item_1.MediaItem, tx).find({ where: { id: (0, typeorm_1.In)(wanted), domain: { id: domain.id } } });
178
+ if (rows.length !== wanted.length)
179
+ throw new shell_1.Refusal('media-item-missing', {}, 'the picture is not in the library any more');
180
+ const byId = new Map(rows.map(one => [one.id, one]));
181
+ return wanted.map(id => byId.get(id));
182
+ }
183
+ /** Whether the request manages the item - its home's writers (decision 5). */
184
+ async function mayManageMedia(item, context) {
185
+ const home = (0, media_purpose_1.mediaPurposeOf)(item.home);
186
+ return !!home && !!context?.state?.user && (await home.mayManage(item, context));
187
+ }
188
+ async function managedOrRefuse(item, context) {
189
+ if (!(await mayManageMedia(item, context)))
190
+ throw new shell_1.Refusal('media-manage-denied', {}, 'only the people who manage the picture change or delete it');
191
+ }
192
+ const DAY = /^\d{4}-\d{2}-\d{2}$/;
193
+ /**
194
+ * Changes a picture's facts - by its home's writers only. The tags and the description are the attachment's. A picture
195
+ * may not come to be shown less far than a record it is used on (decision 4).
196
+ */
197
+ async function updateMediaFacts(itemId, facts, context) {
198
+ const { user, tx } = context.state;
199
+ const [item] = await itemsOrRefuse([itemId], context);
200
+ await managedOrRefuse(item, context);
201
+ if (facts.rightsUntil && !DAY.test(facts.rightsUntil))
202
+ throw new shell_1.Refusal('media-day-invalid', { day: facts.rightsUntil }, 'a day is written YYYY-MM-DD');
203
+ const patch = { updater: user };
204
+ for (const key of ['kind', 'exposure', 'exposureConfirmed', 'origin', 'people'])
205
+ if (facts[key] !== undefined && facts[key] !== null)
206
+ patch[key] = facts[key];
207
+ for (const key of ['title', 'place', 'rightsNote'])
208
+ if (facts[key] !== undefined)
209
+ patch[key] = facts[key]?.trim() || null;
210
+ if (facts.takenAt !== undefined)
211
+ patch.takenAt = facts.takenAt ?? null;
212
+ if (facts.rightsUntil !== undefined)
213
+ patch.rightsUntil = facts.rightsUntil || null;
214
+ const uses = (await (0, shell_1.getRepository)(media_use_1.MediaUse, tx).find({ where: { item: { id: item.id } } })).filter(one => one.targetType !== media_purpose_1.MEDIA_INBOX);
215
+ const after = { ...item, ...patch };
216
+ const narrowing = (0, media_purpose_1.narrowingRefusal)(after, uses);
217
+ if (narrowing)
218
+ throw narrowing;
219
+ /* An outward use of a purpose that asks it keeps asking: no NOT_ASKED people, no ended rights under it. */
220
+ const today = dayOf(new Date());
221
+ for (const use of uses) {
222
+ const purpose = (0, media_purpose_1.mediaPurposeOf)(use.purpose);
223
+ const refusal = purpose && (0, media_purpose_1.useRefusal)(after, purpose, use.targetExposure, today);
224
+ if (refusal)
225
+ throw refusal;
226
+ }
227
+ await (0, shell_1.getRepository)(media_item_1.MediaItem, tx).update(item.id, patch);
228
+ if (item.attachmentId && (facts.tags !== undefined || facts.description !== undefined)) {
229
+ const files = {};
230
+ if (facts.tags !== undefined)
231
+ files.tags = tagsOfMedia(facts.tags);
232
+ if (facts.description !== undefined)
233
+ files.description = facts.description?.trim() || null;
234
+ await (0, shell_1.getRepository)(attachment_base_1.Attachment, tx).update(item.attachmentId, files);
235
+ }
236
+ return (await (0, shell_1.getRepository)(media_item_1.MediaItem, tx).findOneBy({ id: item.id }));
237
+ }
238
+ /** Deletes pictures - by their home's writers, and only those used nowhere (decision 4). */
239
+ async function deleteMediaItems(ids, context) {
240
+ const items = await itemsOrRefuse(ids, context);
241
+ for (const item of items)
242
+ await managedOrRefuse(item, context);
243
+ for (const item of items)
244
+ await deleteMediaItem(item, context);
245
+ return items.length;
246
+ }
247
+ /**
248
+ * Decision 5-2 - shares pictures to another purpose. Each must be managed by the request and its home must declare the
249
+ * route. A route with `accept` puts the picture in the receiving purpose's inbox; otherwise the receiving purpose
250
+ * takes it in itself (`receive` - the gallery makes a post). No file is copied.
251
+ */
252
+ async function shareMedia(itemIds, to, input, context) {
253
+ const { domain, user } = context.state;
254
+ const target = (0, media_purpose_1.purposeOrRefuse)(to);
255
+ const items = await itemsOrRefuse(itemIds, context);
256
+ if (!items.length)
257
+ return 0;
258
+ let accept;
259
+ for (const item of items) {
260
+ await managedOrRefuse(item, context);
261
+ const from = (0, media_purpose_1.purposeOrRefuse)(item.home);
262
+ const refusal = (0, media_purpose_1.shareRefusal)(from, to, item, user.id);
263
+ if (refusal)
264
+ throw refusal;
265
+ const route = from.shareTo.find(one => one.purpose === to);
266
+ if (accept !== undefined && accept !== !!route.accept)
267
+ throw new shell_1.Refusal('media-share-mixed', {}, 'share pictures of one kind at a time');
268
+ accept = !!route.accept;
269
+ }
270
+ if (accept) {
271
+ for (const item of items)
272
+ await useMedia({ itemId: item.id, purpose: to, targetType: media_purpose_1.MEDIA_INBOX, targetId: domain.id }, context);
273
+ return items.length;
274
+ }
275
+ if (!target.receive)
276
+ throw new shell_1.Refusal('media-no-receiver', { to }, `'${to}' takes in no shared picture`);
277
+ await target.receive(items.map(one => one.id), input ?? {}, context);
278
+ return items.length;
279
+ }
280
+ /** The inbox uses of `purpose` for the items - refused when one is not waiting there. */
281
+ async function inboxUsesOrRefuse(items, purpose, context) {
282
+ const { domain, tx } = context.state;
283
+ if (!items.length)
284
+ return [];
285
+ const rows = await (0, shell_1.getRepository)(media_use_1.MediaUse, tx).find({
286
+ where: { domain: { id: domain.id }, purpose, targetType: media_purpose_1.MEDIA_INBOX, targetId: domain.id, item: { id: (0, typeorm_1.In)(items.map(one => one.id)) } }
287
+ });
288
+ if (new Set(rows.map(one => one.itemId)).size !== items.length)
289
+ throw new shell_1.Refusal('media-not-in-inbox', {}, 'the picture is not waiting to be taken in');
290
+ return rows;
291
+ }
292
+ async function receiverOrRefuse(purpose, items, context) {
293
+ const target = (0, media_purpose_1.purposeOrRefuse)(purpose);
294
+ for (const item of items)
295
+ if (!(await target.mayManage(item, context)))
296
+ throw new shell_1.Refusal('media-manage-denied', {}, 'only the people who manage the picture change or delete it');
297
+ return target;
298
+ }
299
+ /** Takes in pictures waiting in the purpose's inbox: the purpose becomes their home (decision 5-2, Q3). */
300
+ async function acceptMedia(itemIds, purpose, context) {
301
+ const { user, tx } = context.state;
302
+ const items = await itemsOrRefuse(itemIds, context);
303
+ await receiverOrRefuse(purpose, items, context);
304
+ const uses = await inboxUsesOrRefuse(items, purpose, context);
305
+ await (0, shell_1.getRepository)(media_item_1.MediaItem, tx).update({ id: (0, typeorm_1.In)(items.map(one => one.id)) }, { home: purpose, updater: user });
306
+ await (0, shell_1.getRepository)(media_use_1.MediaUse, tx).softRemove(uses);
307
+ return items.length;
308
+ }
309
+ /** Sends back pictures waiting in the purpose's inbox - they stay where they came from, as they were. */
310
+ async function declineMedia(itemIds, purpose, context) {
311
+ const { tx } = context.state;
312
+ const items = await itemsOrRefuse(itemIds, context);
313
+ await receiverOrRefuse(purpose, items, context);
314
+ const uses = await inboxUsesOrRefuse(items, purpose, context);
315
+ await (0, shell_1.getRepository)(media_use_1.MediaUse, tx).softRemove(uses);
316
+ return items.length;
317
+ }
318
+ /** The routes a picture of `purpose` may be shared on, to purposes some module declared. */
319
+ function mediaShareRoutesOf(purpose) {
320
+ const from = (0, media_purpose_1.mediaPurposeOf)(purpose);
321
+ return (from?.shareTo ?? [])
322
+ .filter(one => (0, media_purpose_1.mediaPurposeOf)(one.purpose))
323
+ .map(one => ({ purpose: one.purpose, label: (0, media_purpose_1.mediaPurposeOf)(one.purpose).label ?? one.purpose, accept: !!one.accept, ownerOnly: !!one.ownerOnly }));
324
+ }
325
+ //# sourceMappingURL=media-service.js.map
@@ -0,0 +1,27 @@
1
+ import { Domain } from '@things-factory/shell';
2
+ import { User } from '@things-factory/auth-base';
3
+ import { MediaExposure, MediaItem } from './media-item';
4
+ /**
5
+ * 쓰임 - one place a picture is used (ADR-0226 decision 4): a gallery post's photo, an event's photo, a block's
6
+ * figure. The purpose names the module that uses it; the target is that module's record. No copy is made - a picture
7
+ * used in two places is one item with two uses.
8
+ */
9
+ export declare class MediaUse {
10
+ readonly id: string;
11
+ domain?: Domain;
12
+ domainId?: string;
13
+ item?: MediaItem;
14
+ itemId?: string;
15
+ purpose: string;
16
+ targetType: string;
17
+ targetId: string;
18
+ targetExposure: MediaExposure;
19
+ rank: number;
20
+ createdAt?: Date;
21
+ updatedAt?: Date;
22
+ deletedAt?: Date;
23
+ creator?: User;
24
+ creatorId?: string;
25
+ updater?: User;
26
+ updaterId?: string;
27
+ }
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MediaUse = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const typeorm_1 = require("typeorm");
6
+ const type_graphql_1 = require("type-graphql");
7
+ const shell_1 = require("@things-factory/shell");
8
+ const auth_base_1 = require("@things-factory/auth-base");
9
+ const media_item_1 = require("./media-item");
10
+ /**
11
+ * 쓰임 - one place a picture is used (ADR-0226 decision 4): a gallery post's photo, an event's photo, a block's
12
+ * figure. The purpose names the module that uses it; the target is that module's record. No copy is made - a picture
13
+ * used in two places is one item with two uses.
14
+ */
15
+ let MediaUse = class MediaUse {
16
+ };
17
+ exports.MediaUse = MediaUse;
18
+ tslib_1.__decorate([
19
+ (0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
20
+ (0, type_graphql_1.Field)(type => type_graphql_1.ID),
21
+ tslib_1.__metadata("design:type", String)
22
+ ], MediaUse.prototype, "id", void 0);
23
+ tslib_1.__decorate([
24
+ (0, typeorm_1.ManyToOne)(type => shell_1.Domain),
25
+ (0, type_graphql_1.Field)(type => shell_1.Domain, { nullable: true }),
26
+ tslib_1.__metadata("design:type", shell_1.Domain)
27
+ ], MediaUse.prototype, "domain", void 0);
28
+ tslib_1.__decorate([
29
+ (0, typeorm_1.RelationId)((row) => row.domain),
30
+ tslib_1.__metadata("design:type", String)
31
+ ], MediaUse.prototype, "domainId", void 0);
32
+ tslib_1.__decorate([
33
+ (0, typeorm_1.ManyToOne)(type => media_item_1.MediaItem, { nullable: false }),
34
+ tslib_1.__metadata("design:type", media_item_1.MediaItem)
35
+ ], MediaUse.prototype, "item", void 0);
36
+ tslib_1.__decorate([
37
+ (0, typeorm_1.RelationId)((row) => row.item),
38
+ (0, type_graphql_1.Field)({ description: 'Id of the picture used' }),
39
+ tslib_1.__metadata("design:type", String)
40
+ ], MediaUse.prototype, "itemId", void 0);
41
+ tslib_1.__decorate([
42
+ (0, typeorm_1.Column)(),
43
+ (0, type_graphql_1.Field)({ description: 'The purpose it is used for - the module that declared it' }),
44
+ tslib_1.__metadata("design:type", String)
45
+ ], MediaUse.prototype, "purpose", void 0);
46
+ tslib_1.__decorate([
47
+ (0, typeorm_1.Column)(),
48
+ (0, type_graphql_1.Field)({ description: 'The kind of record it is used on' }),
49
+ tslib_1.__metadata("design:type", String)
50
+ ], MediaUse.prototype, "targetType", void 0);
51
+ tslib_1.__decorate([
52
+ (0, typeorm_1.Column)(),
53
+ (0, type_graphql_1.Field)({ description: 'The id of the record it is used on' }),
54
+ tslib_1.__metadata("design:type", String)
55
+ ], MediaUse.prototype, "targetId", void 0);
56
+ tslib_1.__decorate([
57
+ (0, typeorm_1.Column)({ default: media_item_1.MediaExposure.INTERNAL }),
58
+ (0, type_graphql_1.Field)(type => media_item_1.MediaExposure, { description: 'How far the record it is used on is shown' }),
59
+ tslib_1.__metadata("design:type", String)
60
+ ], MediaUse.prototype, "targetExposure", void 0);
61
+ tslib_1.__decorate([
62
+ (0, typeorm_1.Column)({ type: 'int', default: 0 }),
63
+ (0, type_graphql_1.Field)(type => type_graphql_1.Int, { description: 'Its place among the pictures of the record' }),
64
+ tslib_1.__metadata("design:type", Number)
65
+ ], MediaUse.prototype, "rank", void 0);
66
+ tslib_1.__decorate([
67
+ (0, typeorm_1.CreateDateColumn)(),
68
+ (0, type_graphql_1.Field)({ nullable: true, description: 'When it was put there' }),
69
+ tslib_1.__metadata("design:type", Date)
70
+ ], MediaUse.prototype, "createdAt", void 0);
71
+ tslib_1.__decorate([
72
+ (0, typeorm_1.UpdateDateColumn)(),
73
+ (0, type_graphql_1.Field)({ nullable: true, description: 'When it was last changed' }),
74
+ tslib_1.__metadata("design:type", Date)
75
+ ], MediaUse.prototype, "updatedAt", void 0);
76
+ tslib_1.__decorate([
77
+ (0, typeorm_1.DeleteDateColumn)(),
78
+ (0, type_graphql_1.Field)({ nullable: true, description: 'When it was taken off' }),
79
+ tslib_1.__metadata("design:type", Date)
80
+ ], MediaUse.prototype, "deletedAt", void 0);
81
+ tslib_1.__decorate([
82
+ (0, typeorm_1.ManyToOne)(type => auth_base_1.User, { nullable: true }),
83
+ (0, type_graphql_1.Field)(type => auth_base_1.User, { nullable: true }),
84
+ tslib_1.__metadata("design:type", auth_base_1.User)
85
+ ], MediaUse.prototype, "creator", void 0);
86
+ tslib_1.__decorate([
87
+ (0, typeorm_1.RelationId)((row) => row.creator),
88
+ tslib_1.__metadata("design:type", String)
89
+ ], MediaUse.prototype, "creatorId", void 0);
90
+ tslib_1.__decorate([
91
+ (0, typeorm_1.ManyToOne)(type => auth_base_1.User, { nullable: true }),
92
+ (0, type_graphql_1.Field)(type => auth_base_1.User, { nullable: true }),
93
+ tslib_1.__metadata("design:type", auth_base_1.User)
94
+ ], MediaUse.prototype, "updater", void 0);
95
+ tslib_1.__decorate([
96
+ (0, typeorm_1.RelationId)((row) => row.updater),
97
+ tslib_1.__metadata("design:type", String)
98
+ ], MediaUse.prototype, "updaterId", void 0);
99
+ exports.MediaUse = MediaUse = tslib_1.__decorate([
100
+ (0, typeorm_1.Entity)({ name: 'media_uses' }),
101
+ (0, typeorm_1.Index)('ix_media_use_0', (row) => [row.domain, row.purpose, row.targetType, row.targetId]),
102
+ (0, typeorm_1.Index)('ix_media_use_1', (row) => [row.item]),
103
+ (0, type_graphql_1.ObjectType)({ description: 'Entity for MediaUse - one place a picture of the media library is used' })
104
+ ], MediaUse);
105
+ //# sourceMappingURL=media-use.js.map
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@things-factory/media",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "10.1.306",
4
+ "main": "dist-server/index.js",
5
+ "files": [
6
+ "dist-server",
7
+ "things-factory.config.js",
8
+ "translations",
9
+ "!**/*.map",
10
+ "!**/*.test.*",
11
+ "!**/*.spec.*",
12
+ "!**/test/**",
13
+ "!**/tests/**",
14
+ "!**/__tests__/**",
15
+ "!**/*.tsbuildinfo",
16
+ "!**/.DS_Store"
17
+ ],
18
+ "things-factory": true,
19
+ "license": "MIT",
20
+ "author": "heartyoh <heartyoh@hatiolab.com>",
21
+ "description": "The media library - photos and pictures stored once, with their exposure, rights, the people in them and how they were made, used by the modules that declare a purpose (ADR-0226)",
22
+ "publishConfig": {
23
+ "access": "public",
24
+ "@things-factory:registry": "https://registry.npmjs.org"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/hatiolab/things-factory.git",
29
+ "directory": "packages/media"
30
+ },
31
+ "scripts": {
32
+ "build": "npm run build:server",
33
+ "build:server": "npm run clean:server && npx tsc --p ./server/tsconfig.json",
34
+ "clean:server": "rm -rf dist-server",
35
+ "clean": "npm run clean:server",
36
+ "test": "npm run build:server && node --test test/conventions.test.mjs && cd ../.. && npx jest --no-coverage packages/media/"
37
+ },
38
+ "dependencies": {
39
+ "@things-factory/ai-client-base": "^10.1.304",
40
+ "@things-factory/attachment-base": "^10.1.304",
41
+ "@things-factory/auth-base": "^10.1.304",
42
+ "@things-factory/shell": "^10.1.304",
43
+ "graphql-upload": "^15.0.2"
44
+ },
45
+ "devDependencies": {
46
+ "@things-factory/conventions": "^10.1.304"
47
+ },
48
+ "gitHead": "439681f1596540031c5e6446e659277029ce2eb2"
49
+ }
@@ -0,0 +1 @@
1
+ export default {}
@@ -0,0 +1,27 @@
1
+ {
2
+ "error.media-unknown-purpose": "No module declared the media purpose '{purpose}'.",
3
+ "error.media-exposure-narrower": "The picture may be shown only as {exposure}; it cannot be used on a {target} record. Confirm its exposure first.",
4
+ "error.media-people-not-asked": "The people in the picture were not asked, so it cannot be used outside.",
5
+ "error.media-rights-ended": "The rights to the picture ended on {day}; it cannot be used.",
6
+ "error.media-share-not-declared": "Pictures of '{from}' are not shared to '{to}'.",
7
+ "error.media-share-owner-only": "Only the person the picture belongs to can share it.",
8
+ "error.media-item-missing": "The picture was not found. Read the list again.",
9
+ "error.media-item-in-use": "The picture is used in {count} places and cannot be deleted. Take it off them first.",
10
+ "error.media-exposure-in-use": "The picture is used on a record shown as far as {target}, so its exposure cannot be narrowed to {exposure}. Take it off that record first.",
11
+ "error.media-day-invalid": "Write the day as YYYY-MM-DD: {day}",
12
+ "error.media-manage-denied": "Only the people who manage this picture can change or delete it.",
13
+ "error.media-share-mixed": "Share pictures of one kind at a time.",
14
+ "error.media-no-receiver": "Pictures cannot be shared to {to}.",
15
+ "error.media-not-in-inbox": "The picture is no longer waiting to be taken in. Search the list again.",
16
+ "error.media-not-a-picture": "Only image and video files can be uploaded: {name}",
17
+ "error.media-read-denied": "You cannot see the record these pictures belong to.",
18
+ "error.media-add-denied": "Pictures cannot be added here.",
19
+ "error.media-target-incomplete": "Name the record by both its kind and its id.",
20
+ "error.media-no-file": "Choose at least one picture.",
21
+ "error.media-ai-prompt-required": "Say what the picture should show.",
22
+ "error.media-ai-prompt-too-long": "A prompt holds at most {max} characters.",
23
+ "error.media-ai-quality-unknown": "Pick low, medium or high quality.",
24
+ "error.media-ai-size-unknown": "That size is not offered: {size}",
25
+ "error.media-ai-not-allowed": "Pictures for this purpose are not made by AI.",
26
+ "error.media-ai-no-model": "No AI agent here makes pictures. Register an OpenAI or Gemini agent in the AI agent settings."
27
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "error.media-unknown-purpose": "Ningún módulo declaró el uso de medios '{purpose}'.",
3
+ "error.media-exposure-narrower": "La imagen solo puede mostrarse como {exposure}; no puede usarse en un registro {target}. Confirme primero su alcance.",
4
+ "error.media-people-not-asked": "No se pidió permiso a las personas de la imagen, por lo que no puede usarse externamente.",
5
+ "error.media-rights-ended": "Los derechos de la imagen terminaron el {day}; no puede usarse.",
6
+ "error.media-share-not-declared": "Las imágenes de '{from}' no se comparten con '{to}'.",
7
+ "error.media-share-owner-only": "Solo la persona a quien pertenece la imagen puede compartirla.",
8
+ "error.media-item-missing": "No se encontró la imagen. Vuelva a consultar la lista.",
9
+ "error.media-item-in-use": "La imagen se usa en {count} lugares y no puede eliminarse. Quítela primero de ellos.",
10
+ "error.media-exposure-in-use": "La imagen se usa en un registro con visibilidad {target}, por lo que no se puede reducir su visibilidad a {exposure}. Quítela primero de ese registro.",
11
+ "error.media-day-invalid": "Escriba la fecha con el formato AAAA-MM-DD: {day}",
12
+ "error.media-manage-denied": "Solo los responsables de esta imagen pueden modificarla o eliminarla.",
13
+ "error.media-share-mixed": "Comparta imágenes del mismo tipo cada vez.",
14
+ "error.media-no-receiver": "Esta imagen no se puede compartir con {to}.",
15
+ "error.media-not-in-inbox": "La imagen ya no está pendiente de recibir. Vuelva a consultar la lista.",
16
+ "error.media-not-a-picture": "Solo se pueden subir archivos de imagen y vídeo: {name}",
17
+ "error.media-read-denied": "No tiene permiso para ver el registro al que pertenecen estas imágenes.",
18
+ "error.media-add-denied": "Aquí no se pueden subir imágenes.",
19
+ "error.media-target-incomplete": "Indique a la vez el tipo y el ID del registro.",
20
+ "error.media-no-file": "Seleccione al menos una imagen.",
21
+ "error.media-ai-prompt-required": "Describa lo que debe mostrar la imagen.",
22
+ "error.media-ai-prompt-too-long": "La descripción admite como máximo {max} caracteres.",
23
+ "error.media-ai-quality-unknown": "Elija calidad baja, media o alta.",
24
+ "error.media-ai-size-unknown": "Ese tamaño no está disponible: {size}",
25
+ "error.media-ai-not-allowed": "Las imágenes de este uso no se crean con IA.",
26
+ "error.media-ai-no-model": "Ningún agente de IA puede crear imágenes aquí. Registre un agente de OpenAI o Gemini en la configuración de agentes de IA."
27
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "error.media-unknown-purpose": "登録されていない写真の用途({purpose})です。",
3
+ "error.media-exposure-narrower": "この写真の公開範囲は{exposure}のため、{target}の記録には使用できません。先に公開範囲を確認してください。",
4
+ "error.media-people-not-asked": "写真に写っている人物の同意を確認していないため、外部資料には使用できません。",
5
+ "error.media-rights-ended": "写真の使用期限が{day}に終了したため、使用できません。",
6
+ "error.media-share-not-declared": "この写真は{to}に共有できません。",
7
+ "error.media-share-owner-only": "写真の持ち主のみ共有できます。",
8
+ "error.media-item-missing": "写真が見つかりません。一覧を再照会してください。",
9
+ "error.media-item-in-use": "この写真は{count}か所で使用中のため削除できません。先に使用先から外してください。",
10
+ "error.media-exposure-in-use": "この写真は公開範囲が{target}の記録で使用中のため、公開範囲を{exposure}に狭めることはできません。先にその記録から写真の連結を解除してください。",
11
+ "error.media-day-invalid": "日付はYYYY-MM-DD形式で入力してください: {day}",
12
+ "error.media-manage-denied": "この写真を管理する担当者のみが修正または削除できます。",
13
+ "error.media-share-mixed": "同じ種類の写真ごとに共有してください。",
14
+ "error.media-no-receiver": "この写真は{to}に共有できません。",
15
+ "error.media-not-in-inbox": "受け取った写真の一覧にない写真です。一覧を再検索してください。",
16
+ "error.media-not-a-picture": "画像と動画ファイルのみアップロードできます: {name}",
17
+ "error.media-read-denied": "この写真が連結された記録を閲覧する権限がありません。",
18
+ "error.media-add-denied": "ここには写真をアップロードできません。",
19
+ "error.media-target-incomplete": "記録の種類とIDを一緒に指定してください。",
20
+ "error.media-no-file": "写真を1枚以上選択してください。",
21
+ "error.media-ai-prompt-required": "作成する画像の内容を入力してください。",
22
+ "error.media-ai-prompt-too-long": "説明は{max}文字まで入力できます。",
23
+ "error.media-ai-quality-unknown": "品質は低・中・高から選択してください。",
24
+ "error.media-ai-size-unknown": "対応していないサイズです: {size}",
25
+ "error.media-ai-not-allowed": "この用途の画像はAIで作成できません。",
26
+ "error.media-ai-no-model": "画像を作成できるAIエージェントがありません。AIエージェント設定でOpenAIまたはGeminiのエージェントを登録してください。"
27
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "error.media-unknown-purpose": "등록되지 않은 미디어 용도입니다: {purpose}",
3
+ "error.media-exposure-narrower": "이 미디어의 공개 범위가 연결할 기록의 공개 범위보다 좁아 사용할 수 없습니다. 미디어의 공개 범위를 먼저 확인하세요.",
4
+ "error.media-people-not-asked": "미디어에 포함된 인물의 동의를 확인하지 않아 외부 자료에 사용할 수 없습니다.",
5
+ "error.media-rights-ended": "미디어의 사용 기한({day})이 지나 사용할 수 없습니다.",
6
+ "error.media-share-not-declared": "이 미디어는 {to}에 공유할 수 없습니다.",
7
+ "error.media-share-owner-only": "미디어 소유자만 공유할 수 있습니다.",
8
+ "error.media-item-missing": "미디어를 찾을 수 없습니다. 목록을 다시 조회하세요.",
9
+ "error.media-item-in-use": "이 미디어는 {count}곳에서 사용 중이므로 삭제할 수 없습니다. 각 사용처에서 연결을 먼저 해제하세요.",
10
+ "error.media-exposure-in-use": "이 미디어는 공개 범위가 {target}인 기록에서 사용 중이므로 공개 범위를 {exposure}(으)로 좁힐 수 없습니다. 해당 기록과의 연결을 먼저 해제하세요.",
11
+ "error.media-day-invalid": "날짜는 YYYY-MM-DD 형식으로 입력하세요: {day}",
12
+ "error.media-manage-denied": "이 미디어의 관리 담당자만 수정하거나 삭제할 수 있습니다.",
13
+ "error.media-share-mixed": "같은 종류의 미디어끼리 공유하세요.",
14
+ "error.media-no-receiver": "이 미디어는 {to}에 공유할 수 없습니다.",
15
+ "error.media-not-in-inbox": "관리 인수 대기 목록에 없는 미디어입니다. 목록을 다시 조회하세요.",
16
+ "error.media-not-a-picture": "이미지와 동영상 파일만 업로드할 수 있습니다: {name}",
17
+ "error.media-read-denied": "이 미디어가 연결된 기록을 볼 권한이 없습니다.",
18
+ "error.media-add-denied": "이 위치에는 미디어를 업로드할 수 없습니다.",
19
+ "error.media-target-incomplete": "기록의 종류와 ID를 함께 지정하세요.",
20
+ "error.media-no-file": "미디어 파일을 하나 이상 선택하세요.",
21
+ "error.media-ai-prompt-required": "생성할 이미지의 내용을 입력하세요.",
22
+ "error.media-ai-prompt-too-long": "설명은 {max}자까지 입력할 수 있습니다.",
23
+ "error.media-ai-quality-unknown": "품질은 낮음·보통·높음 중에서 선택하세요.",
24
+ "error.media-ai-size-unknown": "지원하지 않는 크기입니다: {size}",
25
+ "error.media-ai-not-allowed": "이 용도의 이미지는 AI로 만들 수 없습니다.",
26
+ "error.media-ai-no-model": "이미지를 만들 수 있는 AI 에이전트가 없습니다. AI 에이전트 설정에서 OpenAI 또는 Gemini 에이전트를 등록하세요."
27
+ }