|
|
@ -2,11 +2,9 @@ import FetchAT from './fetchAT'; |
|
|
|
import { UITypes } from 'nocodb-sdk'; |
|
|
|
import { UITypes } from 'nocodb-sdk'; |
|
|
|
import { Tele } from 'nc-help'; |
|
|
|
import { Tele } from 'nc-help'; |
|
|
|
// import * as sMap from './syncMap';
|
|
|
|
// import * as sMap from './syncMap';
|
|
|
|
import FormData from 'form-data'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { Api } from 'nocodb-sdk'; |
|
|
|
import { Api } from 'nocodb-sdk'; |
|
|
|
|
|
|
|
|
|
|
|
import axios from 'axios'; |
|
|
|
|
|
|
|
import Airtable from 'airtable'; |
|
|
|
import Airtable from 'airtable'; |
|
|
|
import jsonfile from 'jsonfile'; |
|
|
|
import jsonfile from 'jsonfile'; |
|
|
|
import hash from 'object-hash'; |
|
|
|
import hash from 'object-hash'; |
|
|
@ -1368,49 +1366,66 @@ export default async ( |
|
|
|
case UITypes.Attachment: |
|
|
|
case UITypes.Attachment: |
|
|
|
if (!syncDB.options.syncAttachment) rec[key] = null; |
|
|
|
if (!syncDB.options.syncAttachment) rec[key] = null; |
|
|
|
else { |
|
|
|
else { |
|
|
|
const tempArr = []; |
|
|
|
let tempArr = []; |
|
|
|
for (const v of value) { |
|
|
|
// for (const v of value) {
|
|
|
|
const binaryImage = await axios |
|
|
|
// const binaryImage = await axios
|
|
|
|
.get(v.url, { |
|
|
|
// .get(v.url, {
|
|
|
|
responseType: 'stream', |
|
|
|
// responseType: 'stream',
|
|
|
|
headers: { |
|
|
|
// headers: {
|
|
|
|
'Content-Type': v.type |
|
|
|
// 'Content-Type': v.type
|
|
|
|
} |
|
|
|
// }
|
|
|
|
}) |
|
|
|
// })
|
|
|
|
.then(response => { |
|
|
|
// .then(response => {
|
|
|
|
return response.data; |
|
|
|
// return response.data;
|
|
|
|
}) |
|
|
|
// })
|
|
|
|
.catch(error => { |
|
|
|
// .catch(error => {
|
|
|
|
console.log(error); |
|
|
|
// console.log(error);
|
|
|
|
return false; |
|
|
|
// return false;
|
|
|
|
}); |
|
|
|
// });
|
|
|
|
|
|
|
|
//
|
|
|
|
const imageFile: any = new FormData(); |
|
|
|
// const imageFile: any = new FormData();
|
|
|
|
imageFile.append('files', binaryImage, { |
|
|
|
// imageFile.append('files', binaryImage, {
|
|
|
|
filename: v.filename.includes('?') |
|
|
|
// filename: v.filename.includes('?')
|
|
|
|
? v.filename.split('?')[0] |
|
|
|
// ? v.filename.split('?')[0]
|
|
|
|
: v.filename |
|
|
|
// : v.filename
|
|
|
|
}); |
|
|
|
// });
|
|
|
|
|
|
|
|
//
|
|
|
|
const rs = await axios |
|
|
|
// const rs = await axios
|
|
|
|
.post(sDB.baseURL + '/api/v1/db/storage/upload', imageFile, { |
|
|
|
// .post(sDB.baseURL + '/api/v1/db/storage/upload', imageFile, {
|
|
|
|
params: { |
|
|
|
// params: {
|
|
|
|
path: `noco/${sDB.projectName}/${table.title}/${key}` |
|
|
|
// path: `noco/${sDB.projectName}/${table.title}/${key}`
|
|
|
|
}, |
|
|
|
// },
|
|
|
|
headers: { |
|
|
|
// headers: {
|
|
|
|
'Content-Type': `multipart/form-data; boundary=${imageFile._boundary}`, |
|
|
|
// 'Content-Type': `multipart/form-data; boundary=${imageFile._boundary}`,
|
|
|
|
'xc-auth': sDB.authToken |
|
|
|
// 'xc-auth': sDB.authToken
|
|
|
|
} |
|
|
|
// }
|
|
|
|
}) |
|
|
|
// })
|
|
|
|
.then(response => { |
|
|
|
// .then(response => {
|
|
|
|
return response.data; |
|
|
|
// return response.data;
|
|
|
|
}) |
|
|
|
// })
|
|
|
|
.catch(e => { |
|
|
|
// .catch(e => {
|
|
|
|
console.log(e); |
|
|
|
// console.log(e);
|
|
|
|
}); |
|
|
|
// });
|
|
|
|
|
|
|
|
//
|
|
|
|
tempArr.push(...(rs || [])); |
|
|
|
// tempArr.push(...(rs || []));
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
tempArr = await api.storage.uploadByUrl( |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
path: `noco/${sDB.projectName}/${table.title}/${key}` |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
value?.map(attachment => ({ |
|
|
|
|
|
|
|
fileName: attachment.filename, |
|
|
|
|
|
|
|
url: attachment.url, |
|
|
|
|
|
|
|
size: attachment.size, |
|
|
|
|
|
|
|
mimetype: attachment.type |
|
|
|
|
|
|
|
})) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
console.log(e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
rec[key] = JSON.stringify(tempArr); |
|
|
|
rec[key] = JSON.stringify(tempArr); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|