summary refs log tree commit diff stats
path: root/client
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2022-02-04 11:56:54 +0530
committerAndinus <andinus@nand.sh>2022-02-04 11:56:54 +0530
commit3f8a1326dffb01512a1b19a141360180bf6b7fd8 (patch)
tree753b225d500b7dcf92b3141267e982cd790a847d /client
parent1e1e1a0728b2ec8cf42dc943606de13cb33a507c (diff)
downloadvela-3f8a1326dffb01512a1b19a141360180bf6b7fd8.tar.gz
Implement upload functionality
The authentication part on the server is not implemented properly.
Diffstat (limited to 'client')
-rw-r--r--client/src/views/CreateSmiles.vue3
-rw-r--r--client/src/views/ManageSmiles.vue43
2 files changed, 43 insertions, 3 deletions
diff --git a/client/src/views/CreateSmiles.vue b/client/src/views/CreateSmiles.vue
index 7c285f0..88da1f4 100644
--- a/client/src/views/CreateSmiles.vue
+++ b/client/src/views/CreateSmiles.vue
@@ -112,7 +112,8 @@ export default {
                 body: JSON.stringify(data)
             }).then(response => {
                 if (!response.ok)
-                    throw new Error('HTTP error, status = ' + response.status);
+                    throw new Error('HTTP error, status = ' + response.status
+                                    + ' | ' + response.statusText);
                 return response.json();
             }).then(res => {
                 this.id = res.id;
diff --git a/client/src/views/ManageSmiles.vue b/client/src/views/ManageSmiles.vue
index 9a535b7..370b908 100644
--- a/client/src/views/ManageSmiles.vue
+++ b/client/src/views/ManageSmiles.vue
@@ -25,7 +25,10 @@
         </div>
       </div>
       <div class="col-12 md:col-6">
-        <FileUpload name="demo[]" url="/upload" @upload="onUpload" :multiple="true" accept="image/*" :maxFileSize="1000000">
+        <FileUpload @error="onError" @before-send="beforeSend" @upload="onUpload"
+                    name="images" url="http://localhost:9090/upload"
+                    :multiple="true" accept="image/*"
+                    :maxFileSize="2097152"> <!-- 1024 * 1024 * 2 -->
           <template #empty>
             <p>Drag and drop files to here to upload.</p>
           </template>
@@ -61,6 +64,39 @@ export default {
             link.push(this.id);
             return link.join('/');
         },
+        beforeSend(xhr) {
+            xhr.formData.append('id', this.id);
+            xhr.formData.append('auth', this.auth);
+        },
+        onError(error) {
+            this.$toast.add(
+                {severity: 'error',
+                 summary: 'Upload failed',
+                 detail: `${error.xhr.status} ${error.xhr.statusText} | ${error.xhr.response}`});
+        },
+        onUpload(res) {
+            const response = JSON.parse(res.xhr.response);
+            for(let i = 0; i < response.length; i++) {
+                const x = response[i];
+                if (x.stored === false) {
+                    this.$toast.add(
+                        {
+                            severity: 'error',
+                            summary: 'Upload failed',
+                            detail: `${x.filename}: ${x.messages}`
+                        }
+                    );
+                } else if (x.messages.length !== 0) {
+                    this.$toast.add(
+                        {
+                            severity: 'warn',
+                            summary: 'Upload Issues',
+                            detail: `${x.filename}: ${x.messages}`
+                        }
+                    );
+                }
+            }
+        },
         verify() {
             const data = { id: this.id, auth: this.auth };
             const toast = this.$toast;
@@ -73,12 +109,15 @@ export default {
                 referrerPolicy: 'no-referrer',
                 body: JSON.stringify(data)
             }).then(response => {
+                if (response.status === 401)
+                    throw new Error(response.status + ' # ' + 'Authentication Failed');
+                if (response.status === 404)
+                    throw new Error(response.status + ' # ' + 'Smiles deleted or invalid link');
                 if (!response.ok)
                     throw new Error('HTTP error, status = ' + response.status);
                 return response.json();
             }).then(res => {
                 this.name = res.name;
-                console.log(res);
                 this.verified = true;
             }).catch(error => {
                 console.log(error)
/a> 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556