refactor(data): move base64 decoding to _genFile and remove inline data field
- Removed inline base64 decoding (`data` field) from `_documents` definitions - Introduced `_genFile(name)` utility to generate Uint8Array from file name - Simplified `_documents` by eliminating direct `data` property population
This commit is contained in:
parent
a34270cfc3
commit
a88238f209
@ -249,23 +249,10 @@ export const _attributes: Attribute[] = [
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
function base64ToUint8Array(base64: string): Uint8Array {
|
|
||||||
const binaryString = atob(base64); // Decode base64 to binary string
|
|
||||||
const len = binaryString.length;
|
|
||||||
const bytes = new Uint8Array(len);
|
|
||||||
|
|
||||||
for (let i = 0; i < len; i++) {
|
|
||||||
bytes[i] = binaryString.charCodeAt(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const _documents: Doc[] = [
|
export const _documents: Doc[] = [
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
name: "example1.pdf",
|
name: "example1.pdf",
|
||||||
data: base64ToUint8Array(_base64.example1_pdf),
|
|
||||||
addedWhen: new Date("2024-01-12T10:00:00Z"),
|
addedWhen: new Date("2024-01-12T10:00:00Z"),
|
||||||
addedWho: "TekH",
|
addedWho: "TekH",
|
||||||
attributes: [
|
attributes: [
|
||||||
@ -320,12 +307,10 @@ export const _documents: Doc[] = [
|
|||||||
type: 'DATETIME'
|
type: 'DATETIME'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 2,
|
id: 2,
|
||||||
name: "example2.pdf",
|
name: "example2.pdf",
|
||||||
data: base64ToUint8Array(_base64.example2_pdf),
|
|
||||||
addedWhen: new Date("2024-02-03T09:30:00Z"),
|
addedWhen: new Date("2024-02-03T09:30:00Z"),
|
||||||
addedWho: "bob",
|
addedWho: "bob",
|
||||||
changedWhen: new Date("2024-03-15T12:00:00Z"),
|
changedWhen: new Date("2024-03-15T12:00:00Z"),
|
||||||
@ -386,7 +371,6 @@ export const _documents: Doc[] = [
|
|||||||
{
|
{
|
||||||
id: 3,
|
id: 3,
|
||||||
name: "document1.docx",
|
name: "document1.docx",
|
||||||
data: base64ToUint8Array(_base64.document1_docx),
|
|
||||||
addedWhen: new Date("2023-12-20T14:45:00Z"),
|
addedWhen: new Date("2023-12-20T14:45:00Z"),
|
||||||
addedWho: "SchreiberM",
|
addedWho: "SchreiberM",
|
||||||
attributes: [
|
attributes: [
|
||||||
@ -435,7 +419,6 @@ export const _documents: Doc[] = [
|
|||||||
{
|
{
|
||||||
id: 4,
|
id: 4,
|
||||||
name: "spreadsheet1.xlsx",
|
name: "spreadsheet1.xlsx",
|
||||||
data: base64ToUint8Array(_base64.spreadsheet1_xlsx),
|
|
||||||
addedWhen: new Date("2024-05-01T08:15:00Z"),
|
addedWhen: new Date("2024-05-01T08:15:00Z"),
|
||||||
addedWho: "KammM",
|
addedWho: "KammM",
|
||||||
changedWhen: new Date("2024-06-10T16:20:00Z"),
|
changedWhen: new Date("2024-06-10T16:20:00Z"),
|
||||||
@ -486,7 +469,6 @@ export const _documents: Doc[] = [
|
|||||||
{
|
{
|
||||||
id: 5,
|
id: 5,
|
||||||
name: "report.docx",
|
name: "report.docx",
|
||||||
data: base64ToUint8Array(_base64.report_docx),
|
|
||||||
addedWhen: new Date("2024-04-17T11:25:00Z"),
|
addedWhen: new Date("2024-04-17T11:25:00Z"),
|
||||||
addedWho: "SchreiberM",
|
addedWho: "SchreiberM",
|
||||||
attributes: [
|
attributes: [
|
||||||
@ -550,4 +532,32 @@ export const _documents: Doc[] = [
|
|||||||
type: attr.type as Type
|
type: attr.type as Type
|
||||||
}))
|
}))
|
||||||
}))
|
}))
|
||||||
.map(doc => Doc.map(doc));
|
.map(doc => Doc.map(doc));
|
||||||
|
|
||||||
|
function base64ToUint8Array(base64: string): Uint8Array {
|
||||||
|
const binaryString = atob(base64); // Decode base64 to binary string
|
||||||
|
const len = binaryString.length;
|
||||||
|
const bytes = new Uint8Array(len);
|
||||||
|
|
||||||
|
for (let i = 0; i < len; i++) {
|
||||||
|
bytes[i] = binaryString.charCodeAt(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function _genFile(name: string): Uint8Array | undefined {
|
||||||
|
switch (name) {
|
||||||
|
case "example1.pdf":
|
||||||
|
return base64ToUint8Array(_base64.example1_pdf);
|
||||||
|
case "example2.pdf":
|
||||||
|
return base64ToUint8Array(_base64.example2_pdf);
|
||||||
|
case "document1.docx":
|
||||||
|
return base64ToUint8Array(_base64.document1_docx);
|
||||||
|
case "spreadsheet1.xlsx":
|
||||||
|
return base64ToUint8Array(_base64.spreadsheet1_xlsx);
|
||||||
|
case "report.docx":
|
||||||
|
return base64ToUint8Array(_base64.report_docx);
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user