mirror of
https://github.com/stonith404/pingvin-share.git
synced 2024-07-02 07:20:38 +02:00
feat: add email recepients functionality
This commit is contained in:
parent
0efd2d8bf9
commit
32ad43ae27
|
@ -9,3 +9,10 @@ MAX_FILE_SIZE=1000000000
|
||||||
|
|
||||||
# SECURITY
|
# SECURITY
|
||||||
JWT_SECRET=long-random-string
|
JWT_SECRET=long-random-string
|
||||||
|
|
||||||
|
# EMAIL
|
||||||
|
EMAIL_RECIPIENTS_ENABLED=false
|
||||||
|
SMTP_HOST=smtp.example.com
|
||||||
|
SMTP_PORT=587
|
||||||
|
SMTP_EMAIL=pingvin-share@example.com
|
||||||
|
SMTP_PASSWORD=example
|
|
@ -6,3 +6,10 @@ ALLOW_UNAUTHENTICATED_SHARES=false
|
||||||
|
|
||||||
# SECURITY
|
# SECURITY
|
||||||
JWT_SECRET=random-string
|
JWT_SECRET=random-string
|
||||||
|
|
||||||
|
# Email configuration
|
||||||
|
EMAIL_RECIPIENTS_ENABLED=false
|
||||||
|
SMTP_HOST=smtp.example.com
|
||||||
|
SMTP_PORT=587
|
||||||
|
SMTP_EMAIL=pingvin-share@example.com
|
||||||
|
SMTP_PASSWORD=example
|
33
backend/package-lock.json
generated
33
backend/package-lock.json
generated
|
@ -25,6 +25,7 @@
|
||||||
"mime-types": "^2.1.35",
|
"mime-types": "^2.1.35",
|
||||||
"moment": "^2.29.4",
|
"moment": "^2.29.4",
|
||||||
"multer": "^1.4.5-lts.1",
|
"multer": "^1.4.5-lts.1",
|
||||||
|
"nodemailer": "^6.8.0",
|
||||||
"passport": "^0.6.0",
|
"passport": "^0.6.0",
|
||||||
"passport-jwt": "^4.0.0",
|
"passport-jwt": "^4.0.0",
|
||||||
"passport-local": "^1.0.0",
|
"passport-local": "^1.0.0",
|
||||||
|
@ -43,6 +44,7 @@
|
||||||
"@types/mime-types": "^2.1.1",
|
"@types/mime-types": "^2.1.1",
|
||||||
"@types/multer": "^1.4.7",
|
"@types/multer": "^1.4.7",
|
||||||
"@types/node": "^18.7.23",
|
"@types/node": "^18.7.23",
|
||||||
|
"@types/nodemailer": "^6.4.6",
|
||||||
"@types/passport-jwt": "^3.0.7",
|
"@types/passport-jwt": "^3.0.7",
|
||||||
"@types/supertest": "^2.0.12",
|
"@types/supertest": "^2.0.12",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
||||||
|
@ -1214,6 +1216,15 @@
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.23.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.23.tgz",
|
||||||
"integrity": "sha512-DWNcCHolDq0ZKGizjx2DZjR/PqsYwAcYUJmfMWqtVU2MBMG5Mo+xFZrhGId5r/O5HOuMPyQEcM6KUBp5lBZZBg=="
|
"integrity": "sha512-DWNcCHolDq0ZKGizjx2DZjR/PqsYwAcYUJmfMWqtVU2MBMG5Mo+xFZrhGId5r/O5HOuMPyQEcM6KUBp5lBZZBg=="
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/nodemailer": {
|
||||||
|
"version": "6.4.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/nodemailer/-/nodemailer-6.4.6.tgz",
|
||||||
|
"integrity": "sha512-pD6fL5GQtUKvD2WnPmg5bC2e8kWCAPDwMPmHe/ohQbW+Dy0EcHgZ2oCSuPlWNqk74LS5BVMig1SymQbFMPPK3w==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@types/parse-json": {
|
"node_modules/@types/parse-json": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz",
|
||||||
|
@ -5028,6 +5039,14 @@
|
||||||
"integrity": "sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg==",
|
"integrity": "sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/nodemailer": {
|
||||||
|
"version": "6.8.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.8.0.tgz",
|
||||||
|
"integrity": "sha512-EjYvSmHzekz6VNkNd12aUqAco+bOkRe3Of5jVhltqKhEsjw/y0PYPJfp83+s9Wzh1dspYAkUW/YNQ350NATbSQ==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/nopt": {
|
"node_modules/nopt": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz",
|
||||||
|
@ -8303,6 +8322,15 @@
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.23.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.23.tgz",
|
||||||
"integrity": "sha512-DWNcCHolDq0ZKGizjx2DZjR/PqsYwAcYUJmfMWqtVU2MBMG5Mo+xFZrhGId5r/O5HOuMPyQEcM6KUBp5lBZZBg=="
|
"integrity": "sha512-DWNcCHolDq0ZKGizjx2DZjR/PqsYwAcYUJmfMWqtVU2MBMG5Mo+xFZrhGId5r/O5HOuMPyQEcM6KUBp5lBZZBg=="
|
||||||
},
|
},
|
||||||
|
"@types/nodemailer": {
|
||||||
|
"version": "6.4.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/nodemailer/-/nodemailer-6.4.6.tgz",
|
||||||
|
"integrity": "sha512-pD6fL5GQtUKvD2WnPmg5bC2e8kWCAPDwMPmHe/ohQbW+Dy0EcHgZ2oCSuPlWNqk74LS5BVMig1SymQbFMPPK3w==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@types/parse-json": {
|
"@types/parse-json": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz",
|
||||||
|
@ -11224,6 +11252,11 @@
|
||||||
"integrity": "sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg==",
|
"integrity": "sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"nodemailer": {
|
||||||
|
"version": "6.8.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.8.0.tgz",
|
||||||
|
"integrity": "sha512-EjYvSmHzekz6VNkNd12aUqAco+bOkRe3Of5jVhltqKhEsjw/y0PYPJfp83+s9Wzh1dspYAkUW/YNQ350NATbSQ=="
|
||||||
|
},
|
||||||
"nopt": {
|
"nopt": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz",
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
"mime-types": "^2.1.35",
|
"mime-types": "^2.1.35",
|
||||||
"moment": "^2.29.4",
|
"moment": "^2.29.4",
|
||||||
"multer": "^1.4.5-lts.1",
|
"multer": "^1.4.5-lts.1",
|
||||||
|
"nodemailer": "^6.8.0",
|
||||||
"passport": "^0.6.0",
|
"passport": "^0.6.0",
|
||||||
"passport-jwt": "^4.0.0",
|
"passport-jwt": "^4.0.0",
|
||||||
"passport-local": "^1.0.0",
|
"passport-local": "^1.0.0",
|
||||||
|
@ -45,6 +46,7 @@
|
||||||
"@types/mime-types": "^2.1.1",
|
"@types/mime-types": "^2.1.1",
|
||||||
"@types/multer": "^1.4.7",
|
"@types/multer": "^1.4.7",
|
||||||
"@types/node": "^18.7.23",
|
"@types/node": "^18.7.23",
|
||||||
|
"@types/nodemailer": "^6.4.6",
|
||||||
"@types/passport-jwt": "^3.0.7",
|
"@types/passport-jwt": "^3.0.7",
|
||||||
"@types/supertest": "^2.0.12",
|
"@types/supertest": "^2.0.12",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
"@typescript-eslint/eslint-plugin": "^5.40.0",
|
||||||
|
|
|
@ -40,10 +40,19 @@ model Share {
|
||||||
views Int @default(0)
|
views Int @default(0)
|
||||||
expiration DateTime
|
expiration DateTime
|
||||||
|
|
||||||
creatorId String?
|
creatorId String?
|
||||||
creator User? @relation(fields: [creatorId], references: [id])
|
creator User? @relation(fields: [creatorId], references: [id], onDelete: Cascade)
|
||||||
security ShareSecurity?
|
security ShareSecurity?
|
||||||
files File[]
|
recipients ShareRecipient[]
|
||||||
|
files File[]
|
||||||
|
}
|
||||||
|
|
||||||
|
model ShareRecipient {
|
||||||
|
id String @id @default(uuid())
|
||||||
|
email String
|
||||||
|
|
||||||
|
shareId String
|
||||||
|
share Share @relation(fields: [shareId], references: [id], onDelete: Cascade)
|
||||||
}
|
}
|
||||||
|
|
||||||
model File {
|
model File {
|
||||||
|
|
|
@ -13,12 +13,14 @@ import { PrismaService } from "./prisma/prisma.service";
|
||||||
import { ShareController } from "./share/share.controller";
|
import { ShareController } from "./share/share.controller";
|
||||||
import { ShareModule } from "./share/share.module";
|
import { ShareModule } from "./share/share.module";
|
||||||
import { UserController } from "./user/user.controller";
|
import { UserController } from "./user/user.controller";
|
||||||
|
import { EmailModule } from "./email/email.module";
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
AuthModule,
|
AuthModule,
|
||||||
ShareModule,
|
ShareModule,
|
||||||
FileModule,
|
FileModule,
|
||||||
|
EmailModule,
|
||||||
PrismaModule,
|
PrismaModule,
|
||||||
ConfigModule.forRoot({ isGlobal: true }),
|
ConfigModule.forRoot({ isGlobal: true }),
|
||||||
ThrottlerModule.forRoot({
|
ThrottlerModule.forRoot({
|
||||||
|
|
8
backend/src/email/email.module.ts
Normal file
8
backend/src/email/email.module.ts
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import { Module } from "@nestjs/common";
|
||||||
|
import { EmailService } from "./email.service";
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
providers: [EmailService],
|
||||||
|
exports: [EmailService],
|
||||||
|
})
|
||||||
|
export class EmailModule {}
|
35
backend/src/email/email.service.ts
Normal file
35
backend/src/email/email.service.ts
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import { Injectable } from "@nestjs/common";
|
||||||
|
import { ConfigService } from "@nestjs/config";
|
||||||
|
import { User } from "@prisma/client";
|
||||||
|
import * as nodemailer from "nodemailer";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class EmailService {
|
||||||
|
constructor(private config: ConfigService) {}
|
||||||
|
|
||||||
|
// create reusable transporter object using the default SMTP transport
|
||||||
|
transporter = nodemailer.createTransport({
|
||||||
|
host: this.config.get("SMTP_HOST"),
|
||||||
|
port: parseInt(this.config.get("SMTP_PORT")),
|
||||||
|
secure: parseInt(this.config.get("SMTP_PORT")) == 465,
|
||||||
|
auth: {
|
||||||
|
user: this.config.get("SMTP_EMAIL"),
|
||||||
|
pass: this.config.get("SMTP_PASSWORD"),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
async sendMail(recipientEmail: string, shareId: string, creator: User) {
|
||||||
|
const shareUrl = `${this.config.get("APP_URL")}/share/${shareId}`;
|
||||||
|
const creatorIdentifier =
|
||||||
|
creator.firstName && creator.lastName
|
||||||
|
? `${creator.firstName} ${creator.lastName}`
|
||||||
|
: creator.email;
|
||||||
|
|
||||||
|
await this.transporter.sendMail({
|
||||||
|
from: `"Pingvin Share" <${this.config.get("SMTP_EMAIL")}>`,
|
||||||
|
to: recipientEmail,
|
||||||
|
subject: "Files shared with you",
|
||||||
|
text: `Hey!\n${creatorIdentifier} shared some files with you. View or dowload the files with this link: ${shareUrl}.\n Shared securely with Pingvin Share 🐧`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,11 @@
|
||||||
import { Type } from "class-transformer";
|
import { Type } from "class-transformer";
|
||||||
import { IsString, Length, Matches, ValidateNested } from "class-validator";
|
import {
|
||||||
|
IsEmail,
|
||||||
|
IsString,
|
||||||
|
Length,
|
||||||
|
Matches,
|
||||||
|
ValidateNested,
|
||||||
|
} from "class-validator";
|
||||||
import { ShareSecurityDTO } from "./shareSecurity.dto";
|
import { ShareSecurityDTO } from "./shareSecurity.dto";
|
||||||
|
|
||||||
export class CreateShareDTO {
|
export class CreateShareDTO {
|
||||||
|
@ -13,6 +19,9 @@ export class CreateShareDTO {
|
||||||
@IsString()
|
@IsString()
|
||||||
expiration: string;
|
expiration: string;
|
||||||
|
|
||||||
|
@IsEmail({}, { each: true })
|
||||||
|
recipients: string[];
|
||||||
|
|
||||||
@ValidateNested()
|
@ValidateNested()
|
||||||
@Type(() => ShareSecurityDTO)
|
@Type(() => ShareSecurityDTO)
|
||||||
security: ShareSecurityDTO;
|
security: ShareSecurityDTO;
|
||||||
|
|
|
@ -8,6 +8,9 @@ export class MyShareDTO extends ShareDTO {
|
||||||
@Expose()
|
@Expose()
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
|
@Expose()
|
||||||
|
recipients: string[];
|
||||||
|
|
||||||
from(partial: Partial<MyShareDTO>) {
|
from(partial: Partial<MyShareDTO>) {
|
||||||
return plainToClass(MyShareDTO, partial, { excludeExtraneousValues: true });
|
return plainToClass(MyShareDTO, partial, { excludeExtraneousValues: true });
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import { forwardRef, Module } from "@nestjs/common";
|
import { forwardRef, Module } from "@nestjs/common";
|
||||||
import { JwtModule } from "@nestjs/jwt";
|
import { JwtModule } from "@nestjs/jwt";
|
||||||
|
import { EmailModule } from "src/email/email.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({}), forwardRef(() => FileModule)],
|
imports: [JwtModule.register({}), EmailModule, forwardRef(() => FileModule)],
|
||||||
controllers: [ShareController],
|
controllers: [ShareController],
|
||||||
providers: [ShareService],
|
providers: [ShareService],
|
||||||
exports: [ShareService],
|
exports: [ShareService],
|
||||||
|
|
|
@ -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 { EmailService } from "src/email/email.service";
|
||||||
import { FileService } from "src/file/file.service";
|
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";
|
||||||
|
@ -20,6 +21,7 @@ export class ShareService {
|
||||||
constructor(
|
constructor(
|
||||||
private prisma: PrismaService,
|
private prisma: PrismaService,
|
||||||
private fileService: FileService,
|
private fileService: FileService,
|
||||||
|
private emailService: EmailService,
|
||||||
private config: ConfigService,
|
private config: ConfigService,
|
||||||
private jwtService: JwtService
|
private jwtService: JwtService
|
||||||
) {}
|
) {}
|
||||||
|
@ -36,7 +38,7 @@ export class ShareService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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)
|
||||||
let expirationDate;
|
let expirationDate: Date;
|
||||||
if (share.expiration !== "never") {
|
if (share.expiration !== "never") {
|
||||||
expirationDate = moment()
|
expirationDate = moment()
|
||||||
.add(
|
.add(
|
||||||
|
@ -60,6 +62,11 @@ export class ShareService {
|
||||||
expiration: expirationDate,
|
expiration: expirationDate,
|
||||||
creator: { connect: user ? { id: user.id } : undefined },
|
creator: { connect: user ? { id: user.id } : undefined },
|
||||||
security: { create: share.security },
|
security: { create: share.security },
|
||||||
|
recipients: {
|
||||||
|
create: share.recipients
|
||||||
|
? share.recipients.map((email) => ({ email }))
|
||||||
|
: [],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -84,21 +91,33 @@ export class ShareService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async complete(id: string) {
|
async complete(id: string) {
|
||||||
|
const share = await this.prisma.share.findUnique({
|
||||||
|
where: { id },
|
||||||
|
include: { files: true, recipients: true, creator: true },
|
||||||
|
});
|
||||||
|
|
||||||
if (await this.isShareCompleted(id))
|
if (await this.isShareCompleted(id))
|
||||||
throw new BadRequestException("Share already completed");
|
throw new BadRequestException("Share already completed");
|
||||||
|
|
||||||
const moreThanOneFileInShare =
|
if (share.files.length == 0)
|
||||||
(await this.prisma.file.findMany({ where: { shareId: id } })).length != 0;
|
|
||||||
|
|
||||||
if (!moreThanOneFileInShare)
|
|
||||||
throw new BadRequestException(
|
throw new BadRequestException(
|
||||||
"You need at least on file in your share to complete it."
|
"You need at least on file in your share to complete it."
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Asynchronously create a zip of all files
|
||||||
this.createZip(id).then(() =>
|
this.createZip(id).then(() =>
|
||||||
this.prisma.share.update({ where: { id }, data: { isZipReady: true } })
|
this.prisma.share.update({ where: { id }, data: { isZipReady: true } })
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Send email for each recepient
|
||||||
|
for (const recepient of share.recipients) {
|
||||||
|
await this.emailService.sendMail(
|
||||||
|
recepient.email,
|
||||||
|
share.id,
|
||||||
|
share.creator
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return await this.prisma.share.update({
|
return await this.prisma.share.update({
|
||||||
where: { id },
|
where: { id },
|
||||||
data: { uploadLocked: true },
|
data: { uploadLocked: true },
|
||||||
|
@ -106,7 +125,7 @@ export class ShareService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSharesByUser(userId: string) {
|
async getSharesByUser(userId: string) {
|
||||||
return await this.prisma.share.findMany({
|
const shares = await this.prisma.share.findMany({
|
||||||
where: {
|
where: {
|
||||||
creator: { id: userId },
|
creator: { id: userId },
|
||||||
uploadLocked: true,
|
uploadLocked: true,
|
||||||
|
@ -119,7 +138,17 @@ export class ShareService {
|
||||||
orderBy: {
|
orderBy: {
|
||||||
expiration: "desc",
|
expiration: "desc",
|
||||||
},
|
},
|
||||||
|
include: { recipients: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const sharesWithEmailRecipients = shares.map((share) => {
|
||||||
|
return {
|
||||||
|
...share,
|
||||||
|
recipients: share.recipients.map((recipients) => recipients.email),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return sharesWithEmailRecipients;
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(id: string) {
|
async get(id: string) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {
|
||||||
Col,
|
Col,
|
||||||
Grid,
|
Grid,
|
||||||
Group,
|
Group,
|
||||||
|
MultiSelect,
|
||||||
NumberInput,
|
NumberInput,
|
||||||
PasswordInput,
|
PasswordInput,
|
||||||
Select,
|
Select,
|
||||||
|
@ -33,6 +34,7 @@ const showCreateUploadModal = (
|
||||||
uploadCallback: (
|
uploadCallback: (
|
||||||
id: string,
|
id: string,
|
||||||
expiration: string,
|
expiration: string,
|
||||||
|
recipients: string[],
|
||||||
security: ShareSecurity
|
security: ShareSecurity
|
||||||
) => void
|
) => void
|
||||||
) => {
|
) => {
|
||||||
|
@ -54,6 +56,7 @@ const CreateUploadModalBody = ({
|
||||||
uploadCallback: (
|
uploadCallback: (
|
||||||
id: string,
|
id: string,
|
||||||
expiration: string,
|
expiration: string,
|
||||||
|
recipients: string[],
|
||||||
security: ShareSecurity
|
security: ShareSecurity
|
||||||
) => void;
|
) => void;
|
||||||
isSignedIn: boolean;
|
isSignedIn: boolean;
|
||||||
|
@ -79,7 +82,7 @@ const CreateUploadModalBody = ({
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
initialValues: {
|
initialValues: {
|
||||||
link: "",
|
link: "",
|
||||||
|
recipients: [] as string[],
|
||||||
password: undefined,
|
password: undefined,
|
||||||
maxViews: undefined,
|
maxViews: undefined,
|
||||||
expiration_num: 1,
|
expiration_num: 1,
|
||||||
|
@ -110,7 +113,7 @@ const CreateUploadModalBody = ({
|
||||||
const expiration = form.values.never_expires
|
const expiration = form.values.never_expires
|
||||||
? "never"
|
? "never"
|
||||||
: form.values.expiration_num + form.values.expiration_unit;
|
: form.values.expiration_num + form.values.expiration_unit;
|
||||||
uploadCallback(values.link, expiration, {
|
uploadCallback(values.link, expiration, values.recipients, {
|
||||||
password: values.password,
|
password: values.password,
|
||||||
maxViews: values.maxViews,
|
maxViews: values.maxViews,
|
||||||
});
|
});
|
||||||
|
@ -211,7 +214,6 @@ const CreateUploadModalBody = ({
|
||||||
label="Never Expires"
|
label="Never Expires"
|
||||||
{...form.getInputProps("never_expires")}
|
{...form.getInputProps("never_expires")}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Preview expiration date text */}
|
{/* Preview expiration date text */}
|
||||||
<Text
|
<Text
|
||||||
italic
|
italic
|
||||||
|
@ -222,8 +224,32 @@ const CreateUploadModalBody = ({
|
||||||
>
|
>
|
||||||
{ExpirationPreview({ form })}
|
{ExpirationPreview({ form })}
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
<Accordion>
|
<Accordion>
|
||||||
|
<Accordion.Item value="recipients" sx={{ borderBottom: "none" }}>
|
||||||
|
<Accordion.Control>Email recipients</Accordion.Control>
|
||||||
|
<Accordion.Panel>
|
||||||
|
<MultiSelect
|
||||||
|
data={form.values.recipients}
|
||||||
|
placeholder="Enter email recipients"
|
||||||
|
searchable
|
||||||
|
{...form.getInputProps("recipients")}
|
||||||
|
creatable
|
||||||
|
getCreateLabel={(query) => `+ ${query}`}
|
||||||
|
onCreate={(query) => {
|
||||||
|
if (!query.match(/^\S+@\S+\.\S+$/)) {
|
||||||
|
form.setFieldError("recipients", "Invalid email address");
|
||||||
|
} else {
|
||||||
|
form.setFieldError("recipients", null);
|
||||||
|
form.setFieldValue("recipients", [
|
||||||
|
...form.values.recipients,
|
||||||
|
query,
|
||||||
|
]);
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Accordion.Panel>
|
||||||
|
</Accordion.Item>
|
||||||
<Accordion.Item value="security" sx={{ borderBottom: "none" }}>
|
<Accordion.Item value="security" sx={{ borderBottom: "none" }}>
|
||||||
<Accordion.Control>Security options</Accordion.Control>
|
<Accordion.Control>Security options</Accordion.Control>
|
||||||
<Accordion.Panel>
|
<Accordion.Panel>
|
||||||
|
|
|
@ -29,6 +29,7 @@ const Upload = () => {
|
||||||
const uploadFiles = async (
|
const uploadFiles = async (
|
||||||
id: string,
|
id: string,
|
||||||
expiration: string,
|
expiration: string,
|
||||||
|
recipients: string[],
|
||||||
security: ShareSecurity
|
security: ShareSecurity
|
||||||
) => {
|
) => {
|
||||||
setisUploading(true);
|
setisUploading(true);
|
||||||
|
@ -39,7 +40,7 @@ const Upload = () => {
|
||||||
return file;
|
return file;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
share = await shareService.create(id, expiration, security);
|
share = await shareService.create(id, expiration, recipients, security);
|
||||||
for (let i = 0; i < files.length; i++) {
|
for (let i = 0; i < files.length; i++) {
|
||||||
const progressCallBack = (progress: number) => {
|
const progressCallBack = (progress: number) => {
|
||||||
setFiles((files) => {
|
setFiles((files) => {
|
||||||
|
|
|
@ -9,9 +9,11 @@ import api from "./api.service";
|
||||||
const create = async (
|
const create = async (
|
||||||
id: string,
|
id: string,
|
||||||
expiration: string,
|
expiration: string,
|
||||||
|
recipients: string[],
|
||||||
security?: ShareSecurity
|
security?: ShareSecurity
|
||||||
) => {
|
) => {
|
||||||
return (await api.post("shares", { id, expiration, security })).data;
|
return (await api.post("shares", { id, expiration, recipients, security }))
|
||||||
|
.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
const completeShare = async (id: string) => {
|
const completeShare = async (id: string) => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user