diff --git a/pom.xml b/pom.xml index e1abce8..615438d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 tn.mnlr vripper - 2.7.1 + 2.8.0-dev pom org.springframework.boot diff --git a/vripper-electron/package-lock.json b/vripper-electron/package-lock.json index 8533ed7..c88af3e 100644 --- a/vripper-electron/package-lock.json +++ b/vripper-electron/package-lock.json @@ -1,6 +1,6 @@ { "name": "vripper-electron", - "version": "2.7.1", + "version": "2.8.0-dev", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/vripper-electron/package.json b/vripper-electron/package.json index ae5e037..babd1ab 100644 --- a/vripper-electron/package.json +++ b/vripper-electron/package.json @@ -1,6 +1,6 @@ { "name": "vripper-electron", - "version": "2.7.1", + "version": "2.8.0-dev", "description": "A ripper for vipergirls.to built using web technolgies", "main": "main.js", "author": "death-claw <53543762+death-claw@users.noreply.github.com>", diff --git a/vripper-electron/pom.xml b/vripper-electron/pom.xml index ec9be6c..4623df0 100644 --- a/vripper-electron/pom.xml +++ b/vripper-electron/pom.xml @@ -5,7 +5,7 @@ tn.mnlr vripper - 2.7.1 + 2.8.0-dev vripper-electron vripper-electron diff --git a/vripper-server/pom.xml b/vripper-server/pom.xml index 3a89e84..6699347 100644 --- a/vripper-server/pom.xml +++ b/vripper-server/pom.xml @@ -5,7 +5,7 @@ tn.mnlr vripper - 2.7.1 + 2.8.0-dev vripper-server vripper-server diff --git a/vripper-server/src/main/java/tn/mnlr/vripper/web/restendpoints/GalleryEndpoint.java b/vripper-server/src/main/java/tn/mnlr/vripper/web/restendpoints/GalleryEndpoint.java new file mode 100644 index 0000000..1197931 --- /dev/null +++ b/vripper-server/src/main/java/tn/mnlr/vripper/web/restendpoints/GalleryEndpoint.java @@ -0,0 +1,74 @@ +package tn.mnlr.vripper.web.restendpoints; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import tn.mnlr.vripper.services.PathService; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +@RestController +@CrossOrigin(value = "*") +public class GalleryEndpoint { + + private static final Logger logger = LoggerFactory.getLogger(GalleryEndpoint.class); + + @Autowired + private PathService pathService; + + @ExceptionHandler(Exception.class) + public ResponseEntity handleException(Exception e) { + logger.error("Error when process request", e); + return ResponseEntity + .status(HttpStatus.INTERNAL_SERVER_ERROR) + .body(e.getMessage()); + } + + @GetMapping(value = "/image/{postId}/{imgName}", produces = {MediaType.IMAGE_JPEG_VALUE}) + @ResponseStatus(value = HttpStatus.OK) + public synchronized ResponseEntity getImage(@PathVariable("postId") @NonNull String postId, @PathVariable("imgName") @NonNull String imgName) throws Exception { + File destinationFolder = pathService.getDownloadDestinationFolder(postId); + return ResponseEntity.ok(Files.readAllBytes(Paths.get(destinationFolder.toPath().toString(), imgName))); + } + + @GetMapping("/gallery/{postId}") + @ResponseStatus(value = HttpStatus.OK) + public synchronized ResponseEntity> getGallery(@PathVariable("postId") @NonNull String postId) throws Exception { + File destinationFolder = pathService.getDownloadDestinationFolder(postId); + if (destinationFolder.exists() && destinationFolder.isDirectory()) { + return ResponseEntity.ok(Arrays.stream(Objects.requireNonNull(destinationFolder.listFiles())).filter(f -> !f.getName().endsWith("tmp")).map(f -> new GalleryImage(f.getName(), null, f.getName(), f.getName())).collect(Collectors.toList())); + } + return new ResponseEntity("Gallery does not exist in download location, you probably removed it", HttpStatus.BAD_REQUEST); + } +} + +@Getter +@Setter +@NoArgsConstructor +class GalleryImage { + private String img; + private String description; + private String title; + private String alt; + + public GalleryImage(String img, String description, String title, String alt) { + this.img = img; + this.description = description; + this.title = title; + this.alt = alt; + } +} diff --git a/vripper-ui/package-lock.json b/vripper-ui/package-lock.json index a4e061f..eaecc31 100644 --- a/vripper-ui/package-lock.json +++ b/vripper-ui/package-lock.json @@ -1,6 +1,6 @@ { "name": "vripper-ui", - "version": "2.7.1", + "version": "2.8.0-dev", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -2718,6 +2718,14 @@ } } }, + "@ks89/angular-modal-gallery": { + "version": "7.2.5", + "resolved": "https://registry.npmjs.org/@ks89/angular-modal-gallery/-/angular-modal-gallery-7.2.5.tgz", + "integrity": "sha512-WGi0had9OeBb8CgZJyjZPlTaSgYtCEdugH81BoJYMV2i2SpAVrU5zllMwtGw0neurpzOOJyc6B6gGvnvaAee7Q==", + "requires": { + "tslib": "^1.9.0" + } + }, "@ngtools/webpack": { "version": "8.3.20", "resolved": "https://registry.npmjs.org/@ngtools/webpack/-/webpack-8.3.20.tgz", @@ -2802,6 +2810,12 @@ "@types/node": "*" } }, + "@types/hammerjs": { + "version": "2.0.36", + "resolved": "https://registry.npmjs.org/@types/hammerjs/-/hammerjs-2.0.36.tgz", + "integrity": "sha512-7TUK/k2/QGpEAv/BCwSHlYu3NXZhQ9ZwBYpzr9tjlPIL2C5BeGhH3DmVavRx3ZNyELX5TLC91JTz/cen6AAtIQ==", + "dev": true + }, "@types/jasmine": { "version": "2.8.14", "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-2.8.14.tgz", @@ -2823,6 +2837,12 @@ "integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==", "dev": true }, + "@types/mousetrap": { + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/@types/mousetrap/-/mousetrap-1.6.3.tgz", + "integrity": "sha512-13gmo3M2qVvjQrWNseqM3+cR6S2Ss3grbR2NZltgMq94wOwqJYQdgn8qzwDshzgXqMlSUtyPZjysImmktu22ew==", + "dev": true + }, "@types/node": { "version": "8.9.5", "resolved": "https://registry.npmjs.org/@types/node/-/node-8.9.5.tgz", @@ -8663,6 +8683,11 @@ "minimist": "0.0.8" } }, + "mousetrap": { + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/mousetrap/-/mousetrap-1.6.3.tgz", + "integrity": "sha512-bd+nzwhhs9ifsUrC2tWaSgm24/oo2c83zaRyZQF06hYA6sANfsXHtnZ19AbbbDXCDzeH5nZBSQ4NvCjgD62tJA==" + }, "move-concurrently": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz", @@ -10570,6 +10595,11 @@ "tslib": "^1.9.0" } }, + "rxjs-compat": { + "version": "6.5.3", + "resolved": "https://registry.npmjs.org/rxjs-compat/-/rxjs-compat-6.5.3.tgz", + "integrity": "sha512-BIJX2yovz3TBpjJoAZyls2QYuU6ZiCaZ+U96SmxQpuSP/qDUfiXPKOVLbThBB2WZijNHkdTTJXKRwvv5Y48H7g==" + }, "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", diff --git a/vripper-ui/package.json b/vripper-ui/package.json index 3dc4e4a..372c963 100644 --- a/vripper-ui/package.json +++ b/vripper-ui/package.json @@ -1,6 +1,6 @@ { "name": "vripper-ui", - "version": "2.7.1", + "version": "2.8.0-dev", "scripts": { "ng": "ng", "start": "ng serve", @@ -24,12 +24,15 @@ "@angular/platform-browser": "~8.2.14", "@angular/platform-browser-dynamic": "~8.2.14", "@angular/router": "~8.2.14", + "@ks89/angular-modal-gallery": "^7.2.5", "ag-grid-angular": "^22.1.0", "ag-grid-community": "^22.1.0", "core-js": "^2.5.4", "hammerjs": "^2.0.8", + "mousetrap": "^1.6.3", "ngx-electron": "^2.2.0", "rxjs": "~6.5.3", + "rxjs-compat": "^6.5.3", "tslib": "^1.9.0", "zone.js": "~0.8.26" }, @@ -38,8 +41,10 @@ "@angular/cli": "~8.3.20", "@angular/compiler-cli": "^8.2.14", "@angular/language-service": "~8.2.14", + "@types/hammerjs": "^2.0.36", "@types/jasmine": "~2.8.8", "@types/jasminewd2": "~2.0.3", + "@types/mousetrap": "^1.6.3", "@types/node": "~8.9.4", "codelyzer": "~4.5.0", "electron": "^6.0.9", diff --git a/vripper-ui/pom.xml b/vripper-ui/pom.xml index 67d1959..5b7d647 100644 --- a/vripper-ui/pom.xml +++ b/vripper-ui/pom.xml @@ -5,7 +5,7 @@ tn.mnlr vripper - 2.7.1 + 2.8.0-dev vripper-ui vripper-ui diff --git a/vripper-ui/src/app/app.module.ts b/vripper-ui/src/app/app.module.ts index 2ede1db..2906617 100644 --- a/vripper-ui/src/app/app.module.ts +++ b/vripper-ui/src/app/app.module.ts @@ -38,6 +38,8 @@ import { SelectionService } from './selection-service'; import { ToolbarComponent } from './toolbar/toolbar.component'; import { GrabQueueComponent } from './grab-queue/grab-queue.component'; import { UrlGrabRendererComponent } from './grab-queue/url-renderer.component'; +import { GalleryModule } from '@ks89/angular-modal-gallery'; +import { GalleryComponent } from './gallery/gallery.component'; @NgModule({ declarations: [ @@ -60,7 +62,8 @@ import { UrlGrabRendererComponent } from './grab-queue/url-renderer.component'; StatusBarComponent, ToolbarComponent, GrabQueueComponent, - PostContextMenuComponent + PostContextMenuComponent, + GalleryComponent ], entryComponents: [ PostDetailComponent, @@ -69,7 +72,8 @@ import { UrlGrabRendererComponent } from './grab-queue/url-renderer.component'; AppPreviewComponent, ScanComponent, MultiPostComponent, - PostContextMenuComponent + PostContextMenuComponent, + GalleryComponent ], imports: [ BrowserAnimationsModule, @@ -86,7 +90,8 @@ import { UrlGrabRendererComponent } from './grab-queue/url-renderer.component'; UrlRendererComponent, UrlGrabRendererComponent ]), - OverlayModule + OverlayModule, + GalleryModule.forRoot() ], providers: [ AppService, diff --git a/vripper-ui/src/app/gallery/gallery.component.html b/vripper-ui/src/app/gallery/gallery.component.html new file mode 100644 index 0000000..fe3d3ca --- /dev/null +++ b/vripper-ui/src/app/gallery/gallery.component.html @@ -0,0 +1,26 @@ +
+
+

{{ dialogData.title }}

+
+ +
+
+ +
+ +
+
+
+ +
+
+ + + +
diff --git a/vripper-ui/src/app/gallery/gallery.component.scss b/vripper-ui/src/app/gallery/gallery.component.scss new file mode 100644 index 0000000..db089e4 --- /dev/null +++ b/vripper-ui/src/app/gallery/gallery.component.scss @@ -0,0 +1,32 @@ +.container { + height: 100%; +} + +.masonry { + display: flex; + flex-flow: row wrap; + margin-left: -8px; + width: 100%; +} + +.masonry-brick { + flex: auto; + height: 250px; + min-width: 150px; + margin: 0 8px 8px 0; +} + +img { + object-fit: cover; + height: 250px; + width: 250px; +} + +figure { + // background-image: url('http://localhost:8080/image/56661996/001_0001.jpg'); + // background-repeat: no-repeat; + // background-position: 50% 50%; + // background-size: 250px auto; + width: 250px; + height: 250px; +} diff --git a/vripper-ui/src/app/gallery/gallery.component.ts b/vripper-ui/src/app/gallery/gallery.component.ts new file mode 100644 index 0000000..0fe5342 --- /dev/null +++ b/vripper-ui/src/app/gallery/gallery.component.ts @@ -0,0 +1,83 @@ +import { Component, OnInit, ChangeDetectionStrategy, Inject, NgZone, OnDestroy } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { MatDialogRef, MAT_DIALOG_DATA, MatSnackBar } from '@angular/material'; +import { ServerService } from '../server-service'; +import { PostState } from '../posts/post-state.model'; +import { Image, PlainGalleryConfig, PlainGalleryStrategy, AdvancedLayout } from '@ks89/angular-modal-gallery'; +import { ImageData } from '@ks89/angular-modal-gallery/lib/model/image.class'; +import { tap } from 'rxjs/operators'; +import { BehaviorSubject, Subject } from 'rxjs'; + +@Component({ + selector: 'app-gallery', + templateUrl: './gallery.component.html', + styleUrls: ['./gallery.component.scss'], + changeDetection: ChangeDetectionStrategy.OnPush +}) +export class GalleryComponent implements OnInit, OnDestroy { + constructor( + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public dialogData: PostState, + private httpClient: HttpClient, + private serverService: ServerService, + private _snackBar: MatSnackBar, + private ngZone: NgZone + ) {} + + images: Subject = new BehaviorSubject([]); + _images: Image[] = []; + interval; + + customPlainGalleryRowDescConfig: PlainGalleryConfig = { + strategy: PlainGalleryStrategy.CUSTOM, + layout: new AdvancedLayout(-1, true) + }; + + openImageModalRowDescription(image: Image) { + const index: number = this.getCurrentIndexCustomLayout(image, this._images); + this.customPlainGalleryRowDescConfig = Object.assign({}, this.customPlainGalleryRowDescConfig, { + layout: new AdvancedLayout(index, true) + }); + } + + private getCurrentIndexCustomLayout(image: Image, images: Image[]): number { + return image ? images.indexOf(image) : -1; + } + + ngOnInit() { + this.refresh(); + this.interval = setInterval(() => this.refresh(), 5000); + } + + ngOnDestroy() { + if (this.interval != null) { + clearInterval(this.interval); + } + } + + refresh() { + this.httpClient + .get(this.serverService.baseUrl + '/gallery/' + this.dialogData.postId) + .pipe( + tap(v => + v.forEach(i => (i.img = this.serverService.baseUrl + '/image/' + this.dialogData.postId + '/' + i.img)) + ) + ) + .subscribe( + response => { + this.ngZone.run(() => { + this._images = response.map((v, i) => new Image(i, v)); + this.images.next(this._images); + }); + }, + error => { + this.ngZone.run(() => { + this.dialogRef.close(); + this._snackBar.open(error.error || 'Unexpected error, check log file', null, { + duration: 5000 + }); + }); + } + ); + } +} diff --git a/vripper-ui/src/app/home/home.component.scss b/vripper-ui/src/app/home/home.component.scss index 9f0f5dc..b3fa82b 100644 --- a/vripper-ui/src/app/home/home.component.scss +++ b/vripper-ui/src/app/home/home.component.scss @@ -5,3 +5,45 @@ table { :host ::ng-deep .mat-tab-body-wrapper { height: 100%; } + +.app-custom-plain-container-with-desc { + align-items: center; + display: flex; + flex-direction: row; + justify-content: flex-start; + flex-wrap: wrap; + + figure { + margin: 0; + position: relative; + + img { + max-width: 100%; + height: auto; + cursor: pointer; + } + + figcaption { + background: rgba(0, 0, 0, .5); + color: #fff; + font-size: 85%; + padding: 5px; + position: absolute; + bottom: 3px; + left: 0; + right: 0; + } + } + + .description { + font-weight: 400; + text-align: center; + } + + .app-custom-image-with-desc { + height: auto; + margin-right: 2px; + width: 200px; + align-self: start; + } +} \ No newline at end of file diff --git a/vripper-ui/src/app/posts/post-context-menu.component.ts b/vripper-ui/src/app/posts/post-context-menu.component.ts index 20f1352..fa51b6e 100644 --- a/vripper-ui/src/app/posts/post-context-menu.component.ts +++ b/vripper-ui/src/app/posts/post-context-menu.component.ts @@ -1,3 +1,4 @@ +import { GalleryComponent } from './../gallery/gallery.component'; import { ServerService } from './../server-service'; import { HttpClient } from '@angular/common/http'; import { ElectronService } from 'ngx-electron'; @@ -17,7 +18,7 @@ import { RemoveResponse } from '../common/remove-response.model'; @Component({ selector: 'app-post-ctx-menu', template: ` - + +