@zodic/shared 0.0.338 → 0.0.339
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.
- package/app/services/index.ts +1 -2
- package/package.json +1 -1
- package/app/services/ArtifactService.ts +0 -104
package/app/services/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { inject, injectable } from 'inversify';
|
|
2
|
-
import { and, eq } from 'drizzle-orm';
|
|
3
|
-
import { AppContext, schema } from '../..';
|
|
4
|
-
import { BackendCtx } from '../../types/backend';
|
|
5
|
-
import { ArtifactList } from '../../types';
|
|
6
|
-
|
|
7
|
-
@injectable()
|
|
8
|
-
export class ArtifactService {
|
|
9
|
-
constructor(@inject(AppContext) private context: AppContext) {}
|
|
10
|
-
|
|
11
|
-
private async log(
|
|
12
|
-
level: 'info' | 'debug' | 'warn' | 'error',
|
|
13
|
-
message: string,
|
|
14
|
-
context: Record<string, any> = {}
|
|
15
|
-
) {
|
|
16
|
-
const logId = `artifact-service:${Date.now()}`;
|
|
17
|
-
const logMessage = `[${level.toUpperCase()}] ${message}`;
|
|
18
|
-
|
|
19
|
-
console[level](logMessage, context);
|
|
20
|
-
const db = this.context.drizzle();
|
|
21
|
-
try {
|
|
22
|
-
await db
|
|
23
|
-
.insert(schema.logs)
|
|
24
|
-
.values({
|
|
25
|
-
id: logId,
|
|
26
|
-
level,
|
|
27
|
-
message,
|
|
28
|
-
context: JSON.stringify(context),
|
|
29
|
-
createdAt: new Date().getTime(),
|
|
30
|
-
})
|
|
31
|
-
.execute();
|
|
32
|
-
} catch (error) {
|
|
33
|
-
console.error('[ERROR] Failed to persist log to database:', {
|
|
34
|
-
error,
|
|
35
|
-
logId,
|
|
36
|
-
message,
|
|
37
|
-
context,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async generateCosmicMirror(
|
|
43
|
-
artifactId: string,
|
|
44
|
-
userId: string,
|
|
45
|
-
generatedImageId: string,
|
|
46
|
-
archetypeDataId: string,
|
|
47
|
-
size: string
|
|
48
|
-
) {
|
|
49
|
-
await this.log('info', 'Starting cosmic mirror generation', {
|
|
50
|
-
artifactId,
|
|
51
|
-
userId,
|
|
52
|
-
generatedImageId,
|
|
53
|
-
archetypeDataId,
|
|
54
|
-
size
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const drizzle = this.context.drizzle();
|
|
58
|
-
const { artifacts, userArtifacts, generations, userConcepts } = schema;
|
|
59
|
-
|
|
60
|
-
// Implementation will be moved from ArtifactController
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async cleanupStaleCosmicMirror(
|
|
64
|
-
userArtifact: typeof schema.userArtifacts.$inferSelect
|
|
65
|
-
): Promise<void> {
|
|
66
|
-
await this.log('info', 'Cleaning up stale cosmic mirror', {
|
|
67
|
-
userArtifactId: userArtifact.id
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
const drizzle = this.context.drizzle();
|
|
71
|
-
const { generations } = schema;
|
|
72
|
-
|
|
73
|
-
// Delete KV entries
|
|
74
|
-
const kvKeys = await this.context.kvCosmicMirrorManagementStore().list({
|
|
75
|
-
prefix: `cosmic-mirror:${userArtifact.id}:`
|
|
76
|
-
});
|
|
77
|
-
for (const key of kvKeys.keys) {
|
|
78
|
-
await this.context.kvCosmicMirrorManagementStore().delete(key.name);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Delete generations
|
|
82
|
-
await drizzle
|
|
83
|
-
.delete(generations)
|
|
84
|
-
.where(eq(generations.userArtifactId, userArtifact.id));
|
|
85
|
-
|
|
86
|
-
// Delete user artifact
|
|
87
|
-
await drizzle
|
|
88
|
-
.delete(schema.userArtifacts)
|
|
89
|
-
.where(eq(schema.userArtifacts.id, userArtifact.id));
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async retryStaleCosmicMirror(
|
|
93
|
-
userArtifact: typeof schema.userArtifacts.$inferSelect
|
|
94
|
-
): Promise<any> {
|
|
95
|
-
await this.log('info', 'Retrying stale cosmic mirror', {
|
|
96
|
-
userArtifactId: userArtifact.id
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
const drizzle = this.context.drizzle();
|
|
100
|
-
const { users, artifactFaceswap } = schema;
|
|
101
|
-
|
|
102
|
-
// Implementation will be moved from ArtifactController
|
|
103
|
-
}
|
|
104
|
-
}
|