mirror of
https://github.com/stonith404/pingvin-share.git
synced 2024-11-04 23:10:13 +01:00
Merge branch 'development' into main
This commit is contained in:
commit
a4fe49c5cd
@ -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],
|
||||
|
@ -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 } });
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user