0
Fork 0
mirror of https://github.com/stonith404/pingvin-share.git synced 2025-01-29 01:28:59 -05:00

Merge branch 'development' into main

This commit is contained in:
Elias Schneider 2022-10-11 15:14:39 +02:00
commit a4fe49c5cd
4 changed files with 27 additions and 16 deletions

View file

@ -1,12 +1,11 @@
import { Module } from "@nestjs/common"; import { forwardRef, Module } from "@nestjs/common";
import { JwtModule, JwtService } from "@nestjs/jwt"; import { JwtModule } from "@nestjs/jwt";
import { AuthModule } from "src/auth/auth.module";
import { FileModule } from "src/file/file.module"; import { FileModule } from "src/file/file.module";
import { ShareController } from "./share.controller"; import { ShareController } from "./share.controller";
import { ShareService } from "./share.service"; import { ShareService } from "./share.service";
@Module({ @Module({
imports: [JwtModule.register({})], imports: [JwtModule.register({}), forwardRef(() => FileModule)],
controllers: [ShareController], controllers: [ShareController],
providers: [ShareService], providers: [ShareService],
exports: [ShareService], exports: [ShareService],

View file

@ -11,6 +11,7 @@ import * as archiver from "archiver";
import * as argon from "argon2"; import * as argon from "argon2";
import * as fs from "fs"; import * as fs from "fs";
import * as moment from "moment"; import * as moment from "moment";
import { FileService } from "src/file/file.service";
import { PrismaService } from "src/prisma/prisma.service"; import { PrismaService } from "src/prisma/prisma.service";
import { CreateShareDTO } from "./dto/createShare.dto"; import { CreateShareDTO } from "./dto/createShare.dto";
@ -18,7 +19,7 @@ import { CreateShareDTO } from "./dto/createShare.dto";
export class ShareService { export class ShareService {
constructor( constructor(
private prisma: PrismaService, private prisma: PrismaService,
private fileService: FileService,
private config: ConfigService, private config: ConfigService,
private jwtService: JwtService private jwtService: JwtService
) {} ) {}
@ -139,6 +140,7 @@ export class ShareService {
if (!share) throw new NotFoundException("Share not found"); if (!share) throw new NotFoundException("Share not found");
await this.fileService.deleteAllFiles(shareId);
await this.prisma.share.delete({ where: { id: shareId } }); await this.prisma.share.delete({ where: { id: shareId } });
} }

View file

@ -1,5 +1,6 @@
import { Button, Group } from "@mantine/core"; import { Button, Group } from "@mantine/core";
import { useModals } from "@mantine/modals"; import { useModals } from "@mantine/modals";
import axios from "axios";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useState } from "react"; import { useState } from "react";
import Meta from "../components/Meta"; import Meta from "../components/Meta";
@ -11,6 +12,7 @@ import useUser from "../hooks/user.hook";
import shareService from "../services/share.service"; import shareService from "../services/share.service";
import { FileUpload } from "../types/File.type"; import { FileUpload } from "../types/File.type";
import { ShareSecurity } from "../types/share.type"; import { ShareSecurity } from "../types/share.type";
import toast from "../utils/toast.util";
const Upload = () => { const Upload = () => {
const router = useRouter(); const router = useRouter();
@ -49,10 +51,15 @@ const Upload = () => {
setFiles([]); setFiles([]);
} }
} }
} catch { } catch (e) {
files.forEach((file) => { files.forEach((file) => {
file.uploadingState = undefined; file.uploadingState = undefined;
}); });
if (axios.isAxiosError(e)) {
toast.error(e.response?.data?.message ?? "An unkown error occured.");
} else {
toast.error("An unkown error occured.");
}
setFiles([...files]); setFiles([...files]);
setisUploading(false); setisUploading(false);
} }

View file

@ -20,17 +20,20 @@ const signOut = () => {
}; };
const refreshAccessToken = async () => { const refreshAccessToken = async () => {
const currentAccessToken = getCookie("access_token") as string; try {
const currentAccessToken = getCookie("access_token") as string;
if (
currentAccessToken &&
(jose.decodeJwt(currentAccessToken).exp ?? 0) * 1000 <
Date.now() + 2 * 60 * 1000
) {
const refreshToken = getCookie("refresh_token");
if ( const response = await api.post("auth/token", { refreshToken });
currentAccessToken && setCookies("access_token", response.data.accessToken);
(jose.decodeJwt(currentAccessToken).exp ?? 0) * 1000 < }
Date.now() + 2 * 60 * 1000 } catch {
) { console.info("Refresh token invalid or expired");
const refreshToken = getCookie("refresh_token");
const response = await api.post("auth/token", { refreshToken });
setCookies("access_token", response.data.accessToken);
} }
}; };