Compare commits
10 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
932a283d7c | ||
|
|
89ffb6bfe7 | ||
|
|
ddbfc3e25e | ||
|
|
c9a682f502 | ||
| 5727c79cc2 | |||
| 2bcd7506a4 | |||
|
|
31c16befa7 | ||
|
|
e6779f8ec7 | ||
|
|
ce4a8aa94a | ||
|
|
e4e7edff3a |
8 changed files with 687 additions and 389 deletions
|
|
@ -22,7 +22,7 @@ import {
|
|||
listFile,
|
||||
updateFile,
|
||||
} from "../services/edm";
|
||||
import { s3DeleteFile, s3DownloadFile, s3ListFile, s3UploadFile } from "../services/minio";
|
||||
import { s3DeleteFile, s3DownloadFile, s3ListFile, s3UploadFile, truncateFileName } from "../services/minio";
|
||||
|
||||
@Route("api/v1/salary/file/{name}/{group}")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -257,7 +257,7 @@ export class FileController extends Controller {
|
|||
|
||||
const map = fileList.map(async ({ fileName, ...props }) => [
|
||||
fileName,
|
||||
await createFile(path, fileName, props),
|
||||
await createFile(path, truncateFileName(fileName), props),
|
||||
]);
|
||||
|
||||
const result = await Promise.all(map).catch((e) =>
|
||||
|
|
@ -607,7 +607,7 @@ export class SubFileController extends Controller {
|
|||
|
||||
const map = fileList.map(async ({ fileName, ...props }) => [
|
||||
fileName,
|
||||
await createFile(path, fileName, props),
|
||||
await createFile(path, truncateFileName(fileName), props),
|
||||
]);
|
||||
|
||||
const result = await Promise.all(map).catch((e) =>
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -470,7 +470,7 @@ export class SalaryPeriodController extends Controller {
|
|||
const Level = await this.posLevelRepository.findOne({
|
||||
where: {
|
||||
posTypeId: Type.id,
|
||||
posLevelName: salaryProfile.posLevel,
|
||||
posLevelName: salaryProfile.posLevel?.split("/")[0],
|
||||
},
|
||||
});
|
||||
if (!Level) {
|
||||
|
|
@ -935,7 +935,7 @@ export class SalaryPeriodController extends Controller {
|
|||
const Level = await this.posLevelRepository.findOne({
|
||||
where: {
|
||||
posTypeId: Type.id,
|
||||
posLevelName: salaryProfile.posLevel,
|
||||
posLevelName: salaryProfile.posLevel?.split("/")[0],
|
||||
},
|
||||
});
|
||||
if (!Level) {
|
||||
|
|
@ -1272,7 +1272,7 @@ export class SalaryPeriodController extends Controller {
|
|||
const Level = await this.posLevelRepository.findOne({
|
||||
where: {
|
||||
posTypeId: Type.id,
|
||||
posLevelName: salaryProfile.posLevel,
|
||||
posLevelName: salaryProfile.posLevel?.split("/")[0],
|
||||
},
|
||||
});
|
||||
if (!Level) {
|
||||
|
|
@ -1981,7 +1981,7 @@ export class SalaryPeriodController extends Controller {
|
|||
Level = await this.posLevelRepository.findOne({
|
||||
where: {
|
||||
posTypeId: Type.id,
|
||||
posLevelName: salaryProfile.posLevel,
|
||||
posLevelName: salaryProfile.posLevel?.split("/")[0],
|
||||
},
|
||||
});
|
||||
if (!Level) {
|
||||
|
|
@ -2474,7 +2474,7 @@ export class SalaryPeriodController extends Controller {
|
|||
const posLevel = await this.posLevelRepository.findOne({
|
||||
where: {
|
||||
posTypeId: posType.id,
|
||||
posLevelName: salaryProfile.posLevel,
|
||||
posLevelName: salaryProfile.posLevel?.split("/")[0],
|
||||
},
|
||||
});
|
||||
if (!posLevel) {
|
||||
|
|
|
|||
|
|
@ -430,7 +430,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
const Level = await this.posLevelRepository.findOne({
|
||||
where: {
|
||||
posTypeId: Type.id,
|
||||
posLevelName: salaryProfile.posLevel,
|
||||
posLevelName: salaryProfile.posLevel?.split("/")[0],
|
||||
},
|
||||
});
|
||||
if (!Level) {
|
||||
|
|
@ -750,7 +750,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
const Level = await this.posLevelRepository.findOne({
|
||||
where: {
|
||||
posTypeId: Type.id,
|
||||
posLevelName: salaryProfile.posLevel,
|
||||
posLevelName: salaryProfile.posLevel?.split("/")[0],
|
||||
},
|
||||
});
|
||||
if (!Level) {
|
||||
|
|
@ -941,7 +941,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
const Level = await this.posLevelRepository.findOne({
|
||||
where: {
|
||||
posTypeId: Type.id,
|
||||
posLevelName: salaryProfile.posLevel,
|
||||
posLevelName: salaryProfile.posLevel?.split("/")[0],
|
||||
},
|
||||
});
|
||||
if (!Level) {
|
||||
|
|
@ -1132,7 +1132,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
const Level = await this.posLevelRepository.findOne({
|
||||
where: {
|
||||
posTypeId: Type.id,
|
||||
posLevelName: salaryProfile.posLevel,
|
||||
posLevelName: salaryProfile.posLevel?.split("/")[0],
|
||||
},
|
||||
});
|
||||
if (!Level) {
|
||||
|
|
@ -1597,7 +1597,7 @@ export class SalaryPeriodEmployeeController extends Controller {
|
|||
const posLevel = await this.posLevelRepository.findOne({
|
||||
where: {
|
||||
posTypeId: posType.id,
|
||||
posLevelName: salaryProfile.posLevel,
|
||||
posLevelName: salaryProfile.posLevel?.split("/")[0],
|
||||
},
|
||||
});
|
||||
if (!posLevel) {
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ enum EmployeePosLevelAuthoritys {
|
|||
export class EmployeePosLevel extends EntityBase {
|
||||
@Column({
|
||||
comment: "ชื่อระดับชั้นงาน",
|
||||
type: "int",
|
||||
length: 255,
|
||||
})
|
||||
posLevelName: number;
|
||||
posLevelName: string;
|
||||
|
||||
@Column({
|
||||
comment: "ระดับของระดับชั้นงาน",
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ export class SalaryProfileEmployee extends EntityBase {
|
|||
comment: "ระดับตำแหน่ง",
|
||||
default: null,
|
||||
})
|
||||
posLevel: number;
|
||||
posLevel: string;
|
||||
|
||||
@Column({
|
||||
type: "double",
|
||||
|
|
@ -482,7 +482,7 @@ export class CreateSalaryProfileEmployee {
|
|||
posType: string | null;
|
||||
|
||||
@Column()
|
||||
posLevel: number | null;
|
||||
posLevel: string | null;
|
||||
|
||||
@Column()
|
||||
group: number | null;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateTablePosLevelToString20260407112136 implements MigrationInterface {
|
||||
name = 'UpdateTablePosLevelToString20260407112136'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfileEmployee\` CHANGE \`posLevel\` \`posLevel\` varchar(255) NULL COMMENT 'ระดับตำแหน่ง'`);
|
||||
await queryRunner.query(`ALTER TABLE \`employeePosLevel\` CHANGE \`posLevelName\` \`posLevelName\` varchar(255) NOT NULL COMMENT 'ชื่อระดับชั้นงาน'`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`salaryProfileEmployee\` CHANGE \`posLevel\` \`posLevel\` double NULL COMMENT 'ระดับตำแหน่ง'`);
|
||||
await queryRunner.query(`ALTER TABLE \`employeePosLevel\` CHANGE \`posLevelName\` \`posLevelName\` int NOT NULL COMMENT 'ชื่อระดับชั้นงาน'`);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -16,6 +16,26 @@ const minio = new Client({
|
|||
|
||||
export default minio;
|
||||
|
||||
/**
|
||||
* ตัดชื่อไฟล์ถ้ายาวเกิน limit
|
||||
* @param fileName - ชื่อไฟล์เดิม
|
||||
* @param maxLength - ความยาวสูงสุดของชื่อไฟล์ (default: 50 ตัวอักษร ไม่รวมนามสกุล)
|
||||
* @returns ชื่อไฟล์ที่ตัดแล้ว
|
||||
*/
|
||||
export function truncateFileName(fileName: string, maxLength: number = 50): string {
|
||||
const dot = fileName.lastIndexOf(".");
|
||||
const name = dot !== -1 && !fileName.startsWith(".") ? fileName.slice(0, dot) : fileName;
|
||||
const ext = dot !== -1 && !fileName.startsWith(".") ? fileName.slice(dot) : "";
|
||||
|
||||
if (name.length <= maxLength) {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
// ตัดชื่อและเติม "..." ตามด้วย 5 ตัวสุดท้ายของชื่อเดิม
|
||||
const truncated = name.slice(0, maxLength - 8) + "..." + name.slice(-5);
|
||||
return truncated + ext;
|
||||
}
|
||||
|
||||
function exception(e: any): never {
|
||||
console.error(e);
|
||||
throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์");
|
||||
|
|
@ -74,6 +94,11 @@ export async function s3DeleteFolder(path: string) {
|
|||
export async function s3UploadFile(replace: boolean, ...pathname: string[]) {
|
||||
if (!pathname.length) return;
|
||||
|
||||
// ตัดชื่อไฟล์ถ้ายาวเกิน
|
||||
const originalFileName = pathname.at(-1) as string;
|
||||
const truncatedFileName = truncateFileName(originalFileName);
|
||||
pathname = [...pathname.slice(0, -1), truncatedFileName];
|
||||
|
||||
if (!replace) {
|
||||
const list = await s3ListFile(...pathname.slice(0, -1)).catch(exception);
|
||||
|
||||
|
|
@ -146,7 +171,7 @@ export async function s3DownloadFile(...pathname: string[]) {
|
|||
}
|
||||
|
||||
export async function duplicateAvatarFile(refId: string, prefix: string, fileName: string) {
|
||||
try {
|
||||
try {
|
||||
await minio.statObject(MINIO_BUCKET, refId);
|
||||
const avatar = `${prefix}/${fileName}`;
|
||||
await minio.copyObject(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue