1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-07-02 07:20:38 +02: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 { JwtModule, JwtService } from "@nestjs/jwt";
import { AuthModule } from "src/auth/auth.module";
import { forwardRef, Module } from "@nestjs/common";
import { JwtModule } from "@nestjs/jwt";
import { FileModule } from "src/file/file.module";
import { ShareController } from "./share.controller";
import { ShareService } from "./share.service";
@Module({
imports: [JwtModule.register({})],
imports: [JwtModule.register({}), forwardRef(() => FileModule)],
controllers: [ShareController],
providers: [ShareService],
exports: [ShareService],

View File

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

View File

@ -1,5 +1,6 @@
import { Button, Group } from "@mantine/core";
import { useModals } from "@mantine/modals";
import axios from "axios";
import { useRouter } from "next/router";
import { useState } from "react";
import Meta from "../components/Meta";
@ -11,6 +12,7 @@ import useUser from "../hooks/user.hook";
import shareService from "../services/share.service";
import { FileUpload } from "../types/File.type";
import { ShareSecurity } from "../types/share.type";
import toast from "../utils/toast.util";
const Upload = () => {
const router = useRouter();
@ -49,10 +51,15 @@ const Upload = () => {
setFiles([]);
}
}
} catch {
} catch (e) {
files.forEach((file) => {
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]);
setisUploading(false);
}

View File

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