Skip to content

Commit

Permalink
feat(localization): Added thai language (#231)
Browse files Browse the repository at this point in the history
* feat(localization): Added Thai translation

* Formatted

---------

Co-authored-by: Elias Schneider <login@eliasschneider.com>
  • Loading branch information
iUnstable0 and stonith404 committed Aug 17, 2023
1 parent 18c10c0 commit bddb87b
Show file tree
Hide file tree
Showing 35 changed files with 553 additions and 105 deletions.
26 changes: 13 additions & 13 deletions backend/src/auth/auth.controller.ts
Expand Up @@ -33,14 +33,14 @@ export class AuthController {
constructor(
private authService: AuthService,
private authTotpService: AuthTotpService,
private config: ConfigService
private config: ConfigService,
) {}

@Post("signUp")
@Throttle(10, 5 * 60)
async signUp(
@Body() dto: AuthRegisterDTO,
@Res({ passthrough: true }) response: Response
@Res({ passthrough: true }) response: Response,
) {
if (!this.config.get("share.allowRegistration"))
throw new ForbiddenException("Registration is not allowed");
Expand All @@ -50,7 +50,7 @@ export class AuthController {
response = this.addTokensToResponse(
response,
result.refreshToken,
result.accessToken
result.accessToken,
);

return result;
Expand All @@ -61,15 +61,15 @@ export class AuthController {
@HttpCode(200)
async signIn(
@Body() dto: AuthSignInDTO,
@Res({ passthrough: true }) response: Response
@Res({ passthrough: true }) response: Response,
) {
const result = await this.authService.signIn(dto);

if (result.accessToken && result.refreshToken) {
response = this.addTokensToResponse(
response,
result.refreshToken,
result.accessToken
result.accessToken,
);
}

Expand All @@ -81,14 +81,14 @@ export class AuthController {
@HttpCode(200)
async signInTotp(
@Body() dto: AuthSignInTotpDTO,
@Res({ passthrough: true }) response: Response
@Res({ passthrough: true }) response: Response,
) {
const result = await this.authTotpService.signInTotp(dto);

response = this.addTokensToResponse(
response,
result.refreshToken,
result.accessToken
result.accessToken,
);

return new TokenDTO().from(result);
Expand All @@ -113,12 +113,12 @@ export class AuthController {
async updatePassword(
@GetUser() user: User,
@Res({ passthrough: true }) response: Response,
@Body() dto: UpdatePasswordDTO
@Body() dto: UpdatePasswordDTO,
) {
const result = await this.authService.updatePassword(
user,
dto.oldPassword,
dto.password
dto.password,
);

response = this.addTokensToResponse(response, result.refreshToken);
Expand All @@ -129,12 +129,12 @@ export class AuthController {
@HttpCode(200)
async refreshAccessToken(
@Req() request: Request,
@Res({ passthrough: true }) response: Response
@Res({ passthrough: true }) response: Response,
) {
if (!request.cookies.refresh_token) throw new UnauthorizedException();

const accessToken = await this.authService.refreshAccessToken(
request.cookies.refresh_token
request.cookies.refresh_token,
);
response = this.addTokensToResponse(response, undefined, accessToken);
return new TokenDTO().from({ accessToken });
Expand All @@ -143,7 +143,7 @@ export class AuthController {
@Post("signOut")
async signOut(
@Req() request: Request,
@Res({ passthrough: true }) response: Response
@Res({ passthrough: true }) response: Response,
) {
await this.authService.signOut(request.cookies.access_token);
response.cookie("access_token", "accessToken", { maxAge: -1 });
Expand Down Expand Up @@ -176,7 +176,7 @@ export class AuthController {
private addTokensToResponse(
response: Response,
refreshToken?: string,
accessToken?: string
accessToken?: string,
) {
if (accessToken)
response.cookie("access_token", accessToken, { sameSite: "lax" });
Expand Down
12 changes: 6 additions & 6 deletions backend/src/auth/auth.service.ts
Expand Up @@ -21,7 +21,7 @@ export class AuthService {
private prisma: PrismaService,
private jwtService: JwtService,
private config: ConfigService,
private emailService: EmailService
private emailService: EmailService,
) {}

async signUp(dto: AuthRegisterDTO) {
Expand All @@ -39,7 +39,7 @@ export class AuthService {
});

const { refreshToken, refreshTokenId } = await this.createRefreshToken(
user.id
user.id,
);
const accessToken = await this.createAccessToken(user, refreshTokenId);

Expand All @@ -49,7 +49,7 @@ export class AuthService {
if (e.code == "P2002") {
const duplicatedField: string = e.meta.target[0];
throw new BadRequestException(
`A user with this ${duplicatedField} already exists`
`A user with this ${duplicatedField} already exists`,
);
}
}
Expand Down Expand Up @@ -78,7 +78,7 @@ export class AuthService {
}

const { refreshToken, refreshTokenId } = await this.createRefreshToken(
user.id
user.id,
);
const accessToken = await this.createAccessToken(user, refreshTokenId);

Expand Down Expand Up @@ -158,7 +158,7 @@ export class AuthService {
{
expiresIn: "15min",
secret: this.config.get("internal.jwtSecret"),
}
},
);
}

Expand Down Expand Up @@ -189,7 +189,7 @@ export class AuthService {

return this.createAccessToken(
refreshTokenMetaData.user,
refreshTokenMetaData.id
refreshTokenMetaData.id,
);
}

Expand Down
6 changes: 3 additions & 3 deletions backend/src/auth/authTotp.service.ts
Expand Up @@ -18,7 +18,7 @@ export class AuthTotpService {
constructor(
private prisma: PrismaService,
private authService: AuthService,
private config: ConfigService
private config: ConfigService,
) {}

async signInTotp(dto: AuthSignInTotpDTO) {
Expand Down Expand Up @@ -72,7 +72,7 @@ export class AuthTotpService {
await this.authService.createRefreshToken(user.id);
const accessToken = await this.authService.createAccessToken(
user,
refreshTokenId
refreshTokenId,
);

return { accessToken, refreshToken };
Expand All @@ -98,7 +98,7 @@ export class AuthTotpService {
const otpURL = totp.keyuri(
user.username || user.email,
this.config.get("general.appName"),
secret
secret,
);

await this.prisma.user.update({
Expand Down
2 changes: 1 addition & 1 deletion backend/src/auth/decorator/getUser.decorator.ts
Expand Up @@ -5,5 +5,5 @@ export const GetUser = createParamDecorator(
const request = ctx.switchToHttp().getRequest();
const user = request.user;
return data ? user?.[data] : user;
}
},
);
5 changes: 4 additions & 1 deletion backend/src/auth/strategy/jwt.strategy.ts
Expand Up @@ -8,7 +8,10 @@ import { PrismaService } from "src/prisma/prisma.service";

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(config: ConfigService, private prisma: PrismaService) {
constructor(
config: ConfigService,
private prisma: PrismaService,
) {
config.get("internal.jwtSecret");
super({
jwtFromRequest: JwtStrategy.extractJWT,
Expand Down
4 changes: 2 additions & 2 deletions backend/src/clamscan/clamscan.service.ts
Expand Up @@ -19,7 +19,7 @@ export class ClamScanService {

constructor(
private fileService: FileService,
private prisma: PrismaService
private prisma: PrismaService,
) {}

private ClamScan: Promise<NodeClam | null> = new NodeClam()
Expand Down Expand Up @@ -81,7 +81,7 @@ export class ClamScanService {
});

this.logger.warn(
`Share ${shareId} deleted because it contained ${infectedFiles.length} malicious file(s)`
`Share ${shareId} deleted because it contained ${infectedFiles.length} malicious file(s)`,
);
}
}
Expand Down
10 changes: 5 additions & 5 deletions backend/src/config/config.controller.ts
Expand Up @@ -28,7 +28,7 @@ export class ConfigController {
constructor(
private configService: ConfigService,
private logoService: LogoService,
private emailService: EmailService
private emailService: EmailService,
) {}

@Get()
Expand All @@ -41,15 +41,15 @@ export class ConfigController {
@UseGuards(JwtGuard, AdministratorGuard)
async getByCategory(@Param("category") category: string) {
return new AdminConfigDTO().fromList(
await this.configService.getByCategory(category)
await this.configService.getByCategory(category),
);
}

@Patch("admin")
@UseGuards(JwtGuard, AdministratorGuard)
async updateMany(@Body() data: UpdateConfigDTO[]) {
return new AdminConfigDTO().fromList(
await this.configService.updateMany(data)
await this.configService.updateMany(data),
);
}

Expand All @@ -66,9 +66,9 @@ export class ConfigController {
@UploadedFile(
new ParseFilePipe({
validators: [new FileTypeValidator({ fileType: "image/png" })],
})
}),
)
file: Express.Multer.File
file: Express.Multer.File,
) {
return await this.logoService.create(file.buffer);
}
Expand Down
6 changes: 3 additions & 3 deletions backend/src/config/config.service.ts
Expand Up @@ -11,12 +11,12 @@ import { PrismaService } from "src/prisma/prisma.service";
export class ConfigService {
constructor(
@Inject("CONFIG_VARIABLES") private configVariables: Config[],
private prisma: PrismaService
private prisma: PrismaService,
) {}

get(key: `${string}.${string}`): any {
const configVariable = this.configVariables.filter(
(variable) => `${variable.category}.${variable.name}` == key
(variable) => `${variable.category}.${variable.name}` == key,
)[0];

if (!configVariable) throw new Error(`Config variable ${key} not found`);
Expand Down Expand Up @@ -89,7 +89,7 @@ export class ConfigService {
configVariable.type != "text"
) {
throw new BadRequestException(
`Config variable must be of type ${configVariable.type}`
`Config variable must be of type ${configVariable.type}`,
);
}

Expand Down
2 changes: 1 addition & 1 deletion backend/src/config/dto/adminConfig.dto.ts
Expand Up @@ -25,7 +25,7 @@ export class AdminConfigDTO extends ConfigDTO {

fromList(partial: Partial<AdminConfigDTO>[]) {
return partial.map((part) =>
plainToClass(AdminConfigDTO, part, { excludeExtraneousValues: true })
plainToClass(AdminConfigDTO, part, { excludeExtraneousValues: true }),
);
}
}
2 changes: 1 addition & 1 deletion backend/src/config/dto/config.dto.ts
Expand Up @@ -12,7 +12,7 @@ export class ConfigDTO {

fromList(partial: Partial<ConfigDTO>[]) {
return partial.map((part) =>
plainToClass(ConfigDTO, part, { excludeExtraneousValues: true })
plainToClass(ConfigDTO, part, { excludeExtraneousValues: true }),
);
}
}
2 changes: 1 addition & 1 deletion backend/src/config/logo.service.ts
Expand Up @@ -25,7 +25,7 @@ export class LogoService {
fs.promises.writeFile(
`${IMAGES_PATH}/icons/icon-${size}x${size}.png`,
resized,
"binary"
"binary",
);
}
}
Expand Down
18 changes: 9 additions & 9 deletions backend/src/email/email.service.ts
Expand Up @@ -32,7 +32,7 @@ export class EmailService {
await this.getTransporter()
.sendMail({
from: `"${this.config.get("general.appName")}" <${this.config.get(
"smtp.email"
"smtp.email",
)}>`,
to: email,
subject,
Expand All @@ -49,7 +49,7 @@ export class EmailService {
shareId: string,
creator?: User,
description?: string,
expiration?: Date
expiration?: Date,
) {
if (!this.config.get("email.enableShareEmailRecipients"))
throw new InternalServerErrorException("Email service disabled");
Expand All @@ -69,8 +69,8 @@ export class EmailService {
"{expires}",
moment(expiration).unix() != 0
? moment(expiration).fromNow()
: "in: never"
)
: "in: never",
),
);
}

Expand All @@ -83,13 +83,13 @@ export class EmailService {
this.config
.get("email.reverseShareMessage")
.replaceAll("\\n", "\n")
.replaceAll("{shareUrl}", shareUrl)
.replaceAll("{shareUrl}", shareUrl),
);
}

async sendResetPasswordEmail(recipientEmail: string, token: string) {
const resetPasswordUrl = `${this.config.get(
"general.appUrl"
"general.appUrl",
)}/auth/resetPassword/${token}`;

await this.sendMail(
Expand All @@ -98,7 +98,7 @@ export class EmailService {
this.config
.get("email.resetPasswordMessage")
.replaceAll("\\n", "\n")
.replaceAll("{url}", resetPasswordUrl)
.replaceAll("{url}", resetPasswordUrl),
);
}

Expand All @@ -111,15 +111,15 @@ export class EmailService {
this.config
.get("email.inviteMessage")
.replaceAll("{url}", loginUrl)
.replaceAll("{password}", password)
.replaceAll("{password}", password),
);
}

async sendTestMail(recipientEmail: string) {
await this.getTransporter()
.sendMail({
from: `"${this.config.get("general.appName")}" <${this.config.get(
"smtp.email"
"smtp.email",
)}>`,
to: recipientEmail,
subject: "Test email",
Expand Down

0 comments on commit bddb87b

Please sign in to comment.