fix some bugs

This commit is contained in:
rubikscraft 2022-09-10 14:45:14 +02:00
parent 74eb9a2503
commit 6621a167e7
No known key found for this signature in database
GPG key ID: 1463EBE9200A5CD4
6 changed files with 60 additions and 48 deletions

View file

@ -3,7 +3,7 @@ import multipart from '@fastify/multipart';
import { NestFactory, Reflector } from '@nestjs/core';
import {
FastifyAdapter,
NestFastifyApplication,
NestFastifyApplication
} from '@nestjs/platform-fastify';
import { AppModule } from './app.module';
import { UserDbService } from './collections/user-db/user-db.service';
@ -16,6 +16,8 @@ import { MainAuthGuard } from './managers/auth/guards/main.guard';
import { HelmetOptions } from './security';
async function bootstrap() {
const isProduction = process.env['PICSUR_PRODUCTION'] !== undefined;
// Create fasify
const fastifyAdapter = new FastifyAdapter();
// TODO: generic error messages
@ -27,7 +29,7 @@ async function bootstrap() {
AppModule,
fastifyAdapter,
{
bufferLogs: false,
bufferLogs: isProduction,
},
);

View file

@ -1,27 +1,40 @@
<div class="dialog-text">
<div class="row">
<div class="col-12">
<h1>Edit Image Properties</h1>
<form (ngSubmit)="save()">
<div class="row">
<div class="col-12">
<h1>Edit Image</h1>
</div>
<div class="col-12">
<mat-form-field appearance="outline" color="accent">
<mat-label>Title</mat-label>
<input
matInput
type="text"
[ngModelOptions]="{ standalone: true }"
[(ngModel)]="image.file_name"
/>
</mat-form-field>
</div>
<div class="col-12">
<mat-form-field>
<mat-label>Expires After</mat-label>
<mat-select
[ngModelOptions]="{ standalone: true }"
[(ngModel)]="expiresAfter"
>
<mat-option
*ngFor="let option of ExpireOptions"
[value]="option[1]"
>
{{ option[0] }}
</mat-option>
</mat-select>
</mat-form-field>
</div>
</div>
<div class="col-12">
<mat-form-field appearance="outline" color="accent">
<mat-label>Title</mat-label>
<input matInput type="text" [(ngModel)]="image.file_name" />
</mat-form-field>
<div class="dialog-buttons">
<button type="button" mat-flat-button (click)="close()">CANCEL</button>
<button type="submit" mat-raised-button color="accent">SAVE</button>
</div>
<div class="col-12">
<mat-form-field>
<mat-label>Expires After</mat-label>
<mat-select [(value)]="expiresAfter">
<mat-option *ngFor="let option of ExpireOptions" [value]="option[1]">
{{ option[0] }}
</mat-option>
</mat-select>
</mat-form-field>
</div>
</div>
<div class="dialog-buttons">
<button mat-flat-button (click)="close()">CANCEL</button>
<button mat-raised-button color="accent" (click)="save()">SAVE</button>
</div>
</form>
</div>

View file

@ -18,11 +18,11 @@ export interface EditDialogData {
export class EditDialogComponent implements OnInit {
private readonly logger = new Logger(EditDialogComponent.name);
public readonly ExpireOptions: Array<[string, null | number]> = [
public readonly ExpireOptions: Array<[string, number]> = [
['Never', 0],
['5 Minutes', 5 * 60],
['10 Minutes', 10 * 60],
['30 Minutes', 15 * 60],
['30 Minutes', 30 * 60],
['1 Hour', 60 * 60],
['6 Hours', 2 * 60 * 60],
['12 Hours', 12 * 60 * 60],
@ -31,7 +31,7 @@ export class EditDialogComponent implements OnInit {
['1 Month', 30 * 24 * 60 * 60],
];
public expiresAfter: number = 0;
public expiresAfter?: number = undefined;
public image: EImage;
constructor(
@ -50,16 +50,13 @@ export class EditDialogComponent implements OnInit {
async ngOnInit() {}
close() {
this.dialogRef.close(null);
this.dialogRef.close();
}
async save() {
const result = await this.imageService.UpdateImage(this.image.id, {
file_name: this.image.file_name,
expires_at:
this.expiresAfter === 0
? null
: new Date(Date.now() + this.expiresAfter * 1000),
expires_at: this.getExpiresDate(),
});
if (HasFailed(result)) {
@ -71,4 +68,10 @@ export class EditDialogComponent implements OnInit {
this.dialogRef.close(result);
}
private getExpiresDate() {
if (this.expiresAfter === undefined) return undefined;
if (this.expiresAfter === 0) return null;
return new Date(Date.now() + this.expiresAfter * 1000);
}
}

View file

@ -66,12 +66,12 @@
[open-on-hover]="true"
(main-click)="download()"
>
<button mat-mini-fab matTooltip="Customize Image" (click)="customize()">
<mat-icon fontSet="material-icons-outlined"> tune </mat-icon>
</button>
<button mat-mini-fab matTooltip="Share image" (click)="share()">
<mat-icon fontSet="material-icons-outlined"> share </mat-icon>
</button>
<button mat-mini-fab matTooltip="Customize Image" (click)="customize()">
<mat-icon fontSet="material-icons-outlined"> tune </mat-icon>
</button>
<button
*ngIf="canManage"
mat-mini-fab

View file

@ -6,7 +6,7 @@ import {
AnimFileType,
FileType,
ImageFileType,
SupportedFileTypeCategory,
SupportedFileTypeCategory
} from 'picsur-shared/dist/dto/mimes.dto';
import { Permission } from 'picsur-shared/dist/dto/permissions.enum';
@ -26,11 +26,11 @@ import { UtilService } from 'src/app/util/util.service';
import {
CustomizeDialogComponent,
CustomizeDialogData,
CustomizeDialogData
} from './customize-dialog/customize-dialog.component';
import {
EditDialogComponent,
EditDialogData,
EditDialogData
} from './edit-dialog/edit-dialog.component';
@Component({
@ -192,9 +192,6 @@ export class ViewComponent implements OnInit {
await this.dialogService.showCustomDialog(
CustomizeDialogComponent,
options,
{
dismissable: false,
},
);
}
@ -208,12 +205,9 @@ export class ViewComponent implements OnInit {
const res: EImage | null = await this.dialogService.showCustomDialog(
EditDialogComponent,
options,
{
dismissable: false,
},
);
if (res !== null) {
if (res) {
this.image = res;
}
}

View file

@ -4,7 +4,7 @@ import { MatDialog } from '@angular/material/dialog';
import { Logger } from 'src/app/services/logger/logger.service';
import {
ConfirmDialogComponent,
ConfirmDialogData,
ConfirmDialogData
} from './confirm-dialog/confirm-dialog.component';
@Injectable({
@ -26,7 +26,7 @@ export class DialogService {
const ref = this.dialog.open(component, {
data,
panelClass: 'small-dialog-padding',
...(options?.dismissable === false
...(options?.dismissable !== false
? {}
: { disableClose: true, closeOnNavigation: false }),
maxHeight: '90vh',