Skip to content

Commit

Permalink
Merge pull request #23 from foghorn-tech/fix-backup-csv-ks-0713
Browse files Browse the repository at this point in the history
[Fix] backup csv - bad request params
  • Loading branch information
ObservedObserver authored Jul 17, 2023
2 parents 98f57fc + da34045 commit bc0e2d2
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/rath-client/src/loggers/dataImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { IGeoRole, ISemanticType } from "@kanaries/loa";
import { IMuteFieldBase, IRawField, IRow } from "../interfaces"
import { request } from "../utils/request";
import { getMainServiceAddress } from "../utils/user";
import { RATH_INDEX_COLUMN_KEY } from "../constants";

const DATA_SOURCE_LOGGER_URL =
'https://1423108296428281.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/Rath/dataSourceLogger/'
Expand Down Expand Up @@ -70,9 +71,11 @@ async function createFileDataset(workspaceName: string, name: string, file: File
name,
desc: `Generated by Rath. [${new Date().toLocaleString()}]`,
meta: {
type: 'JSON',
encoding: 'utf8',
type: 'TEXT_FILE',
extractHeader: true,
fileSize: file.size,
separator: ',',
encoding: 'utf8',
},
});
await fetch(uploadUrl, {
Expand Down Expand Up @@ -189,11 +192,12 @@ export async function putCloudDataset (props: PutCloudDatasetProps) {
return;
}
const { name, data, fields, workspaceName } = props;
const originFields = fields.filter(f => f.fid !== RATH_INDEX_COLUMN_KEY);
try {
const file = new File([jsonToCsv(fields, data)], `${name}.csv`, { type: 'text/csv' });
const { datasetId } = await createFileDataset(workspaceName, name, file);
const file = new File([jsonToCsv(originFields, data)], `${name}.csv`.replace(/\.csv$/, ''), { type: 'text/csv' });
const { datasetId } = await createFileDataset(workspaceName, name.replace(/\.[^.]+$/, ''), file);
const { fieldsMeta } = await waitUntilDatasetDraftReady(datasetId);
await confirmDatasetDraft(datasetId, fields, fieldsMeta);
await confirmDatasetDraft(datasetId, originFields, fieldsMeta);
// eslint-disable-next-line no-console
console.info('putCloudDataset success. datasetId: ', datasetId);
} catch (error) {
Expand Down

0 comments on commit bc0e2d2

Please sign in to comment.