1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-10-01 00:50:10 +02:00

fix: share fails if a share was created with a reverse share link recently

This commit is contained in:
Elias Schneider 2023-02-10 10:58:49 +01:00
parent 5d1a7f0310
commit edc10b72b7
No known key found for this signature in database
GPG Key ID: 07E623B294202B6C

View File

@ -44,12 +44,11 @@ export class ShareService {
let expirationDate: Date; let expirationDate: Date;
// If share is created by a reverse share token override the expiration date // If share is created by a reverse share token override the expiration date
if (reverseShareToken) { const reverseShare = await this.reverseShareService.getByToken(
const { shareExpiration } = await this.reverseShareService.getByToken(
reverseShareToken reverseShareToken
); );
if (reverseShare) {
expirationDate = shareExpiration; expirationDate = reverseShare.shareExpiration;
} else { } else {
// We have to add an exception for "never" (since moment won't like that) // We have to add an exception for "never" (since moment won't like that)
if (share.expiration !== "never") { if (share.expiration !== "never") {
@ -84,12 +83,14 @@ export class ShareService {
}, },
}); });
if (reverseShareToken) { if (reverseShare) {
// Assign share to reverse share token // Assign share to reverse share token
await this.prisma.reverseShare.update({ await this.prisma.reverseShare.update({
where: { token: reverseShareToken }, where: { token: reverseShareToken },
data: { data: {
shareId: share.id, shares: {
connect: { id: shareTuple.id },
},
}, },
}); });
} }
@ -164,10 +165,10 @@ export class ShareService {
// Check if any file is malicious with ClamAV // Check if any file is malicious with ClamAV
this.clamScanService.checkAndRemove(share.id); this.clamScanService.checkAndRemove(share.id);
if (reverseShareToken) { if (share.reverseShare) {
await this.prisma.reverseShare.update({ await this.prisma.reverseShare.update({
where: { token: reverseShareToken }, where: { token: reverseShareToken },
data: { used: true }, data: { remainingUses: { decrement: 1 } },
}); });
} }