Add Photo Viewer

This commit is contained in:
death-claw
2019-12-21 17:23:22 +01:00
parent c6ef54e115
commit 18e2bc6afc
18 changed files with 344 additions and 14 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>tn.mnlr</groupId>
<artifactId>vripper</artifactId>
<version>2.7.1</version>
<version>2.8.0-dev</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "vripper-electron",
"version": "2.7.1",
"version": "2.8.0-dev",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
+1 -1
View File
@@ -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>",
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<groupId>tn.mnlr</groupId>
<artifactId>vripper</artifactId>
<version>2.7.1</version>
<version>2.8.0-dev</version>
</parent>
<artifactId>vripper-electron</artifactId>
<name>vripper-electron</name>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<groupId>tn.mnlr</groupId>
<artifactId>vripper</artifactId>
<version>2.7.1</version>
<version>2.8.0-dev</version>
</parent>
<artifactId>vripper-server</artifactId>
<name>vripper-server</name>
@@ -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<byte[]> 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<List<GalleryImage>> 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;
}
}
+31 -1
View File
@@ -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",
+6 -1
View File
@@ -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",
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<groupId>tn.mnlr</groupId>
<artifactId>vripper</artifactId>
<version>2.7.1</version>
<version>2.8.0-dev</version>
</parent>
<artifactId>vripper-ui</artifactId>
<name>vripper-ui</name>
+8 -3
View File
@@ -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,
@@ -0,0 +1,26 @@
<div class="dialog-container" fxLayout="column" style="height: 100%;">
<div fxFlex="nogrow">
<h2 class="no-wrap" mat-dialog-title>{{ dialogData.title }}</h2>
</div>
<mat-dialog-content fxFlex="grow">
<div class="container">
<div class="masonry ">
<ng-container *ngFor="let img of images | async">
<figure class="masonry-brick ">
<img (click)="openImageModalRowDescription(img)" [src]="img.modal.img"/>
</figure>
</ng-container>
</div>
<ks-modal-gallery
[dotsConfig]="{ visible: false }"
[id]="0"
[modalImages]="images | async"
[plainGalleryConfig]="customPlainGalleryRowDescConfig"
[previewConfig]="{ visible: false }"
></ks-modal-gallery>
</div>
</mat-dialog-content>
<mat-dialog-actions align="end" fxFlex="nogrow">
<button mat-dialog-close mat-raised-button>Close</button>
</mat-dialog-actions>
</div>
@@ -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;
}
@@ -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<GalleryComponent>,
@Inject(MAT_DIALOG_DATA) public dialogData: PostState,
private httpClient: HttpClient,
private serverService: ServerService,
private _snackBar: MatSnackBar,
private ngZone: NgZone
) {}
images: Subject<Image[]> = 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<ImageData[]>(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
});
});
}
);
}
}
@@ -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;
}
}
@@ -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: `
<mat-card>
<mat-card class="mat-elevation-z4">
<mat-action-list>
<button
(click)="restart()"
@@ -47,6 +48,10 @@ import { RemoveResponse } from '../common/remove-response.model';
<mat-icon>list</mat-icon>
<span>Files</span>
</button>
<button (click)="openGallery()" mat-list-item>
<mat-icon>photo_library</mat-icon>
<span>View Photos</span>
</button>
<button (click)="open()" *ngIf="electronService.isElectronApp" mat-list-item>
<mat-icon>open_in_new</mat-icon>
<span>Download Location</span>
@@ -180,6 +185,33 @@ export class PostContextMenuComponent {
});
}
openGallery() {
this.contextMenuService.closePostCtxtMenu();
this.ngZone.run(() => {
const dialogRef = this.dialog.open(GalleryComponent, {
width: '90%',
height: '90%',
maxWidth: '100vw',
maxHeight: '100vh',
data: this.postState
});
const smallDialogSubscription = this.isExtraSmall.subscribe(result => {
if (result.matches) {
dialogRef.updateSize('100%', '100%');
} else {
dialogRef.updateSize('90%', '90%');
}
});
dialogRef.afterClosed().subscribe(() => {
if (smallDialogSubscription != null) {
smallDialogSubscription.unsubscribe();
}
});
});
}
open() {
this.contextMenuService.closePostCtxtMenu();
if (!this.electronService.isElectronApp) {
@@ -1,5 +1,5 @@
export const environment = {
production: true,
localhost: '',
version: '2.7.1'
version: '2.8.0-dev'
};
+1 -1
View File
@@ -5,7 +5,7 @@
export const environment = {
production: false,
localhost: 'http://localhost:8080',
version: '2.7.1'
version: '2.8.0-dev'
};
/*
+1
View File
@@ -5,6 +5,7 @@ import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
import 'hammerjs';
import 'mousetrap';
if (environment.production) {
enableProdMode();