Merge branch 'release' into staging

4e4d3706862d426e865f6ffdf13b6d131bc050d1

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +34 -14Showing whitespace changes
src/endpoints/sprites.js+34 -14
@@ -71,9 +71,16 @@ export function importRisuSprites(directories, data) {
7171 }
7272
7373 // Create sprites folder if it doesn't exist
7474 const spritesPath = path.joingetSpritesPath(directories.characters, name, false);
75+
76+ // Invalid sprites path
77+ if (!spritesPath) {
78+ return;
79+ }
80+
81+ // Create sprites folder if it doesn't exist
7582 if (!fs.existsSync(spritesPath)) {
7683 fs.mkdirSync(spritesPath, { recursive: true });
7784 }
7885
7986 // Path to sprites is not a directory. This should never happen.
@@ -94,7 +101,7 @@ export function importRisuSprites(directories, data) {
94101 }
95102
96103 const filename = label + '.png';
97104 const pathToFile = path.join(spritesPath, sanitize(filename));
98105 writeFileAtomicSync(pathToFile, fileBase64, { encoding: 'base64' });
99106 }
100107
@@ -145,7 +152,8 @@ router.get('/get', function (request, response) {
145152
146153router.post('/delete', async (request, response) => {
147154 const label = request.body.label;
148155 const name = String(request.body.name);
156+ const isSubfolder = name.includes('/');
149157 const spriteName = request.body.spriteName || label;
150158
151159 if (!spriteName || !name) {
@@ -153,10 +161,10 @@ router.post('/delete', async (request, response) => {
153161 }
154162
155163 try {
156164 const spritesPath = path.joingetSpritesPath(request.user.directories.characters, name, isSubfolder);
157165
158166 // No sprites folder exists, or not a directory
159167 if (!spritesPath || !fs.existsSync(spritesPath) || !fs.statSync(spritesPath).isDirectory()) {
160168 return response.sendStatus(404);
161169 }
162170
@@ -178,18 +186,24 @@ router.post('/delete', async (request, response) => {
178186
179187router.post('/upload-zip', async (request, response) => {
180188 const file = request.file;
181189 const name = String(request.body.name);
190+ const isSubfolder = name.includes('/');
182191
183192 if (!file || !name) {
184193 return response.sendStatus(400);
185194 }
186195
187196 try {
188197 const spritesPath = path.joingetSpritesPath(request.user.directories.characters, name, isSubfolder);
198+
199+ // Invalid sprites path
200+ if (!spritesPath) {
201+ return response.sendStatus(400);
202+ }
189203
190204 // Create sprites folder if it doesn't exist
191205 if (!fs.existsSync(spritesPath)) {
192206 fs.mkdirSync(spritesPath, { recursive: true });
193207 }
194208
195209 // Path to sprites is not a directory. This should never happen.
@@ -210,7 +224,7 @@ router.post('/upload-zip', async (request, response) => {
210224 }
211225
212226 // Write sprite buffer to disk
213227 const pathToSprite = path.join(spritesPath, sanitize(filename));
214228 writeFileAtomicSync(pathToSprite, buffer);
215229 }
216230
@@ -226,7 +240,8 @@ router.post('/upload-zip', async (request, response) => {
226240router.post('/upload', async (request, response) => {
227241 const file = request.file;
228242 const label = request.body.label;
229243 const name = String(request.body.name);
244+ const isSubfolder = name.includes('/');
230245 const spriteName = request.body.spriteName || label;
231246
232247 if (!file || !label || !name) {
@@ -234,11 +249,16 @@ router.post('/upload', async (request, response) => {
234249 }
235250
236251 try {
237252 const spritesPath = path.joingetSpritesPath(request.user.directories.characters, name, isSubfolder);
253+
254+ // Invalid sprites path
255+ if (!spritesPath) {
256+ return response.sendStatus(400);
257+ }
238258
239259 // Create sprites folder if it doesn't exist
240260 if (!fs.existsSync(spritesPath)) {
241261 fs.mkdirSync(spritesPath, { recursive: true });
242262 }
243263
244264 // Path to sprites is not a directory. This should never happen.
@@ -257,7 +277,7 @@ router.post('/upload', async (request, response) => {
257277
258278 const filename = spriteName + path.parse(file.originalname).ext;
259279 const spritePath = path.join(file.destination, file.filename);
260280 const pathToFile = path.join(spritesPath, sanitize(filename));
261281 // Copy uploaded file to sprites folder
262282 fs.cpSync(spritePath, pathToFile);
263283 // Remove uploaded file