|
@@ -346,25 +346,64 @@ export class VideoMediaService {
|
|
|
throw new BadRequestException('Empty file');
|
|
throw new BadRequestException('Empty file');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const workbook = XLSX.read(buffer, { type: 'buffer' });
|
|
|
|
|
- const sheetName = workbook.SheetNames[0];
|
|
|
|
|
- const sheet = sheetName ? workbook.Sheets[sheetName] : undefined;
|
|
|
|
|
|
|
+ const rowsAH: Array<{ idRaw: unknown; tagsRaw: unknown }> = [];
|
|
|
|
|
|
|
|
- if (!sheet) {
|
|
|
|
|
- throw new BadRequestException('No sheet found in Excel file');
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ const workbook = XLSX.read(buffer, { type: 'buffer' });
|
|
|
|
|
+ const sheetName = workbook.SheetNames[0];
|
|
|
|
|
+ const sheet = sheetName ? workbook.Sheets[sheetName] : undefined;
|
|
|
|
|
|
|
|
- const rangeRef = sheet['!ref'] ?? 'A1:A1';
|
|
|
|
|
- const range = XLSX.utils.decode_range(rangeRef);
|
|
|
|
|
- const rowsAH: Array<{ idRaw: unknown; tagsRaw: unknown }> = [];
|
|
|
|
|
|
|
+ if (!sheet) {
|
|
|
|
|
+ throw new BadRequestException('No sheet found in Excel file');
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- for (let r = range.s.r; r <= range.e.r; r += 1) {
|
|
|
|
|
- const idCell = sheet[XLSX.utils.encode_cell({ r, c: 0 })];
|
|
|
|
|
- const tagsCell = sheet[XLSX.utils.encode_cell({ r, c: 7 })];
|
|
|
|
|
- rowsAH.push({
|
|
|
|
|
- idRaw: idCell?.v ?? '',
|
|
|
|
|
- tagsRaw: tagsCell?.v ?? '',
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ const rangeRef = sheet['!ref'] ?? 'A1:A1';
|
|
|
|
|
+ const range = XLSX.utils.decode_range(rangeRef);
|
|
|
|
|
+
|
|
|
|
|
+ for (let r = range.s.r; r <= range.e.r; r += 1) {
|
|
|
|
|
+ const idCell = sheet[XLSX.utils.encode_cell({ r, c: 0 })];
|
|
|
|
|
+ const tagsCell = sheet[XLSX.utils.encode_cell({ r, c: 7 })];
|
|
|
|
|
+ rowsAH.push({
|
|
|
|
|
+ idRaw: idCell?.v ?? '',
|
|
|
|
|
+ tagsRaw: tagsCell?.v ?? '',
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ const cellToString = (value: unknown): string => {
|
|
|
|
|
+ if (value == null) return '';
|
|
|
|
|
+ if (typeof value === 'string') return value;
|
|
|
|
|
+ if (typeof value === 'number' || typeof value === 'boolean') {
|
|
|
|
|
+ return String(value);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (typeof value === 'object') {
|
|
|
|
|
+ const anyValue = value as any;
|
|
|
|
|
+ if (typeof anyValue.text === 'string') return anyValue.text;
|
|
|
|
|
+ if (Array.isArray(anyValue.richText)) {
|
|
|
|
|
+ return anyValue.richText.map((t: any) => t?.text ?? '').join('');
|
|
|
|
|
+ }
|
|
|
|
|
+ if (typeof anyValue.result !== 'undefined') {
|
|
|
|
|
+ return String(anyValue.result);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return String(value);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const workbook = new ExcelJS.Workbook();
|
|
|
|
|
+ await workbook.xlsx.load(buffer as any);
|
|
|
|
|
+ const sheet = workbook.worksheets[0];
|
|
|
|
|
+
|
|
|
|
|
+ if (!sheet) {
|
|
|
|
|
+ throw new BadRequestException('No sheet found in Excel file');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const lastRow = sheet.lastRow?.number ?? 0;
|
|
|
|
|
+ for (let r = 1; r <= lastRow; r += 1) {
|
|
|
|
|
+ const row = sheet.getRow(r);
|
|
|
|
|
+ rowsAH.push({
|
|
|
|
|
+ idRaw: cellToString(row.getCell(1).value),
|
|
|
|
|
+ tagsRaw: cellToString(row.getCell(8).value),
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
this.logger.log(
|
|
this.logger.log(
|