@xenterprises/fastify-ximagepipeline 1.1.0 → 1.2.0
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/LICENSE +60 -0
- package/README.md +211 -441
- package/package.json +2 -2
- package/src/routes/status.js +7 -9
- package/src/routes/upload.js +12 -17
- package/src/utils/image.js +71 -85
- package/src/workers/processor.js +39 -30
- package/src/xImagePipeline.js +93 -22
- package/FILES.md +0 -212
- package/IMPLEMENTATION_SUMMARY.md +0 -427
- package/INTEGRATION_GUIDE.md +0 -554
- package/SCHEMA.prisma +0 -113
- package/test/xImagePipeline.test.js +0 -196
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
// test/xImagePipeline.test.js
|
|
2
|
-
import { test } from "node:test";
|
|
3
|
-
import assert from "node:assert";
|
|
4
|
-
import Fastify from "fastify";
|
|
5
|
-
import multipart from "@fastify/multipart";
|
|
6
|
-
import xImagePipeline from "../src/xImagePipeline.js";
|
|
7
|
-
|
|
8
|
-
// Mock database
|
|
9
|
-
const mockDb = {
|
|
10
|
-
mediaQueue: {
|
|
11
|
-
create: async (data) => ({
|
|
12
|
-
id: "test-job-" + Date.now(),
|
|
13
|
-
...data.data,
|
|
14
|
-
}),
|
|
15
|
-
findUnique: async (query) => ({
|
|
16
|
-
id: query.where.id,
|
|
17
|
-
status: "COMPLETE",
|
|
18
|
-
sourceType: "avatar",
|
|
19
|
-
sourceId: "user123",
|
|
20
|
-
}),
|
|
21
|
-
findFirst: async () => null,
|
|
22
|
-
update: async (query) => ({ count: 1 }),
|
|
23
|
-
updateMany: async () => ({ count: 0 }),
|
|
24
|
-
},
|
|
25
|
-
media: {
|
|
26
|
-
create: async (data) => ({
|
|
27
|
-
id: "media-123",
|
|
28
|
-
...data.data,
|
|
29
|
-
}),
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// Mock R2 config
|
|
34
|
-
const mockR2Config = {
|
|
35
|
-
endpoint: "https://example.r2.cloudflarestorage.com",
|
|
36
|
-
region: "auto",
|
|
37
|
-
accessKeyId: "mock-key",
|
|
38
|
-
secretAccessKey: "mock-secret",
|
|
39
|
-
bucket: "test-bucket",
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
test("xImagePipeline Plugin - registers successfully with required config", async () => {
|
|
43
|
-
const fastify = Fastify({ logger: false });
|
|
44
|
-
try {
|
|
45
|
-
await fastify.register(multipart);
|
|
46
|
-
await fastify.register(xImagePipeline, {
|
|
47
|
-
r2: mockR2Config,
|
|
48
|
-
db: mockDb,
|
|
49
|
-
});
|
|
50
|
-
assert.ok(true, "Plugin registered successfully");
|
|
51
|
-
} finally {
|
|
52
|
-
try {
|
|
53
|
-
await fastify.close();
|
|
54
|
-
} catch {
|
|
55
|
-
// Ignore
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test("xImagePipeline Plugin - throws error without R2 config", async () => {
|
|
61
|
-
const fastify = Fastify({ logger: false });
|
|
62
|
-
try {
|
|
63
|
-
await assert.rejects(
|
|
64
|
-
async () => {
|
|
65
|
-
await fastify.register(multipart);
|
|
66
|
-
await fastify.register(xImagePipeline, {
|
|
67
|
-
db: mockDb,
|
|
68
|
-
});
|
|
69
|
-
},
|
|
70
|
-
/R2 configuration is required/
|
|
71
|
-
);
|
|
72
|
-
} finally {
|
|
73
|
-
try {
|
|
74
|
-
await fastify.close();
|
|
75
|
-
} catch {
|
|
76
|
-
// Ignore
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test("xImagePipeline Plugin - throws error without database", async () => {
|
|
82
|
-
const fastify = Fastify({ logger: false });
|
|
83
|
-
try {
|
|
84
|
-
await assert.rejects(
|
|
85
|
-
async () => {
|
|
86
|
-
await fastify.register(multipart);
|
|
87
|
-
await fastify.register(xImagePipeline, {
|
|
88
|
-
r2: mockR2Config,
|
|
89
|
-
});
|
|
90
|
-
},
|
|
91
|
-
/Database instance/
|
|
92
|
-
);
|
|
93
|
-
} finally {
|
|
94
|
-
try {
|
|
95
|
-
await fastify.close();
|
|
96
|
-
} catch {
|
|
97
|
-
// Ignore
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
test("xImagePipeline Routes - GET /media/status/:jobId returns job status", async () => {
|
|
103
|
-
const fastify = Fastify({ logger: false });
|
|
104
|
-
try {
|
|
105
|
-
await fastify.register(multipart);
|
|
106
|
-
await fastify.register(xImagePipeline, {
|
|
107
|
-
r2: mockR2Config,
|
|
108
|
-
db: mockDb,
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const response = await fastify.inject({
|
|
112
|
-
method: "GET",
|
|
113
|
-
url: "/image-pipeline/status/test-job-123",
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
assert.equal(response.statusCode, 200);
|
|
117
|
-
const body = JSON.parse(response.payload);
|
|
118
|
-
assert.ok(body.jobId, "Response should have jobId");
|
|
119
|
-
assert.ok(body.status, "Response should have status");
|
|
120
|
-
} finally {
|
|
121
|
-
try {
|
|
122
|
-
await fastify.close();
|
|
123
|
-
} catch {
|
|
124
|
-
// Ignore
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
test("xImagePipeline Configuration - accepts custom variants config", async () => {
|
|
130
|
-
const fastify = Fastify({ logger: false });
|
|
131
|
-
const customConfig = {
|
|
132
|
-
r2: mockR2Config,
|
|
133
|
-
db: mockDb,
|
|
134
|
-
variants: {
|
|
135
|
-
custom: {
|
|
136
|
-
xs: { width: 100, height: 100, fit: "cover" },
|
|
137
|
-
lg: { width: 800, height: 600, fit: "inside" },
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
try {
|
|
142
|
-
await fastify.register(multipart);
|
|
143
|
-
await fastify.register(xImagePipeline, customConfig);
|
|
144
|
-
assert.ok(true, "Plugin registered with custom variants");
|
|
145
|
-
} finally {
|
|
146
|
-
try {
|
|
147
|
-
await fastify.close();
|
|
148
|
-
} catch {
|
|
149
|
-
// Ignore
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test("xImagePipeline Configuration - accepts worker configuration", async () => {
|
|
155
|
-
const fastify = Fastify({ logger: false });
|
|
156
|
-
const configWithWorker = {
|
|
157
|
-
r2: mockR2Config,
|
|
158
|
-
db: mockDb,
|
|
159
|
-
worker: {
|
|
160
|
-
enabled: true,
|
|
161
|
-
pollInterval: 10000,
|
|
162
|
-
maxAttempts: 5,
|
|
163
|
-
},
|
|
164
|
-
};
|
|
165
|
-
try {
|
|
166
|
-
await fastify.register(multipart);
|
|
167
|
-
await fastify.register(xImagePipeline, configWithWorker);
|
|
168
|
-
assert.ok(true, "Plugin registered with worker config");
|
|
169
|
-
} finally {
|
|
170
|
-
try {
|
|
171
|
-
await fastify.close();
|
|
172
|
-
} catch {
|
|
173
|
-
// Ignore
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
test("xImagePipeline Variant Presets - has predefined variant presets", async () => {
|
|
179
|
-
const fastify = Fastify({ logger: false });
|
|
180
|
-
try {
|
|
181
|
-
await fastify.register(multipart);
|
|
182
|
-
await fastify.register(xImagePipeline, {
|
|
183
|
-
r2: mockR2Config,
|
|
184
|
-
db: mockDb,
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
// Just verify plugin registered - variants are available via plugin configuration
|
|
188
|
-
assert.ok(true, "Plugin has variant presets configured");
|
|
189
|
-
} finally {
|
|
190
|
-
try {
|
|
191
|
-
await fastify.close();
|
|
192
|
-
} catch {
|
|
193
|
-
// Ignore
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
});
|