MCPcopy Index your code
hub / github.com/chartbrew/chartbrew / parseUpload

Function parseUpload

server/api/ProjectRoute.js:162–259  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

160 }
161
162 const parseUpload = () => {
163 return new Promise((resolve, reject) => {
164 let hasFile = false;
165 let fileCount = 0;
166 let settled = false;
167 const uploadDirectory = path.resolve(__dirname, "../uploads");
168
169 const fail = (status, message) => {
170 if (settled) return;
171 settled = true;
172 reject({ status, message });
173 };
174
175 const succeed = (value) => {
176 if (settled) return;
177 settled = true;
178 resolve(value);
179 };
180
181 req.pipe(req.busboy);
182
183 req.busboy.on("file", (fieldName, file, info) => {
184 fileCount += 1;
185 if (fileCount > 1) {
186 file.resume();
187 fail(400, "Only one logo file can be uploaded");
188 return;
189 }
190
191 hasFile = true;
192 const mimeType = `${info?.mimeType || ""}`.toLowerCase();
193 if (!isAllowedLogoMimeType(mimeType)) {
194 file.resume();
195 fail(415, "Unsupported file type. Only png, jpg, gif, webp, and svg are allowed");
196 return;
197 }
198
199 const chunks = [];
200 let totalSize = 0;
201
202 file.on("data", (chunk) => {
203 if (settled) return;
204
205 totalSize += chunk.length;
206 if (totalSize > MAX_LOGO_UPLOAD_SIZE_BYTES) {
207 file.resume();
208 fail(413, "Logo exceeds maximum size (5MB)");
209 return;
210 }
211
212 chunks.push(chunk);
213 });
214
215 file.on("error", () => {
216 fail(400, "Could not process uploaded file");
217 });
218
219 file.on("end", async () => {

Callers 1

ProjectRoute.jsFile · 0.85

Calls 7

failFunction · 0.85
isAllowedLogoMimeTypeFunction · 0.85
isValidLogoImageBufferFunction · 0.85
buildSafeLogoFilenameFunction · 0.85
resolveSafeUploadPathFunction · 0.85
succeedFunction · 0.85
onMethod · 0.80

Tested by

no test coverage detected