Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Kholid060 authored Feb 24, 2022
2 parents 71081ca + 405a1db commit a122904
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 37 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "automa",
"version": "1.0.2",
"version": "1.1.0",
"description": "An extension for automating your browser by connecting blocks",
"license": "MIT",
"repository": {
Expand Down
8 changes: 8 additions & 0 deletions src/components/newtab/workflow/edit/EditExportData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
{{ type.name }}
</option>
</ui-select>
<ui-checkbox
v-if="data.type === 'csv'"
:model-value="data.addBOMHeader"
class="mt-2"
@change="updateData({ addBOMHeader: $event })"
>
{{ t('workflow.blocks.export-data.bomHeader') }}
</ui-checkbox>
</div>
</template>
<script setup>
Expand Down
2 changes: 1 addition & 1 deletion src/components/newtab/workflow/edit/EditLoopData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function updateLoopID(id) {
}
function importFile() {
openFilePicker(['application/json', 'text/csv', 'application/vnd.ms-excel'])
.then(async (fileObj) => {
.then(async ([fileObj]) => {
if (fileObj.size > maxFileSize) {
toast.error(t('message.maxSizeExceeded'));
return;
Expand Down
2 changes: 1 addition & 1 deletion src/content/blocks-handler/handler-get-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function getText(block) {
} = block.data;

if (regexData) {
regex = new RegExp(regexData, regexExp.join(''));
regex = new RegExp(regexData, [...new Set(regexExp)].join(''));
}

handleSelector(block, {
Expand Down
1 change: 1 addition & 0 deletions src/locales/en/blocks.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
"description": "Export workflow data",
"exportAs": "Export as",
"refKey": "Reference key",
"bomHeader": "Add UTF-8 BOM",
"dataToExport": {
"placeholder": "Data to export",
"options": {
Expand Down
2 changes: 1 addition & 1 deletion src/newtab/pages/Workflows.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<v-remixicon name="riCompass3Line" class="mr-2 -ml-1" />
{{ t('workflow.browse') }}
</ui-button>
<ui-button @click="importWorkflow">
<ui-button @click="importWorkflow({ multiple: true })">
<v-remixicon name="riUploadLine" class="mr-2 -ml-1" />
{{ t('workflow.import') }}
</ui-button>
Expand Down
21 changes: 4 additions & 17 deletions src/newtab/pages/settings/Backup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -215,29 +215,16 @@ function backupWorkflows() {
}
async function restoreWorkflows() {
try {
const file = await openFilePicker('application/json');
const [file] = await openFilePicker('application/json');
const reader = new FileReader();
const insertWorkflows = (workflows) => {
workflows.forEach((workflow) => {
const isWorkflowExists = Workflow.query()
.where('id', workflow.id)
.exists();
if (!state.updateIfExists || !isWorkflowExists) {
const newWorkflows = workflows.map((workflow) => {
if (!state.updateIfExists) {
workflow.createdAt = Date.now();
delete workflow.id;
Workflow.insert({
data: workflow,
});
return;
}
Workflow.update({
where: workflow.id,
data: workflow,
});
return workflow;
});
const showMessage = (event) => {
toast(
Expand Down
10 changes: 8 additions & 2 deletions src/utils/data-exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function generateJSON(keys, data) {
return result;
}

export default function (data, { name, type }, converted) {
export default function (data, { name, type, addBOMHeader }, converted) {
let result = data;

if (type === 'csv' || type === 'json') {
Expand All @@ -54,8 +54,14 @@ export default function (data, { name, type }, converted) {
).join(' ');
}

const payload = [result];

if (addBOMHeader) {
payload.unshift(new Uint8Array([0xef, 0xbb, 0xbf]));
}

const { mime, ext } = files[type];
const blob = new Blob([result], {
const blob = new Blob(payload, {
type: mime,
});

Expand Down
16 changes: 9 additions & 7 deletions src/utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function replaceMustache(str, replacer) {
}

export function openFilePicker(acceptedFileTypes = [], attrs = {}) {
return new Promise((resolve, reject) => {
return new Promise((resolve) => {
const input = document.createElement('input');
input.type = 'file';
input.accept = Array.isArray(acceptedFileTypes)
Expand All @@ -110,14 +110,16 @@ export function openFilePicker(acceptedFileTypes = [], attrs = {}) {
});

input.onchange = (event) => {
const file = event.target.files[0];
const { files } = event.target;
const validFiles = [];

if (!file || !acceptedFileTypes.includes(file.type)) {
reject(new Error(`Invalid ${file.type} file type`));
return;
}
files.forEach((file) => {
if (!acceptedFileTypes.includes(file.type)) return;

validFiles.push(file);
});

resolve(file);
resolve(validFiles);
};

input.click();
Expand Down
1 change: 1 addition & 0 deletions src/utils/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ export const tasks = {
refKey: '',
type: 'json',
description: '',
addBOMHeader: false,
dataToExport: 'data-columns',
},
},
Expand Down
17 changes: 10 additions & 7 deletions src/utils/workflow-data.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { parseJSON, fileSaver, openFilePicker, isObject } from './helper';
import Workflow from '@/models/workflow';

export function importWorkflow() {
openFilePicker(['application/json'])
.then((file) => {
const reader = new FileReader();
export function importWorkflow(attrs = {}) {
openFilePicker(['application/json'], attrs)
.then((files) => {
const getDrawflow = ({ drawflow }) => {
if (isObject(drawflow)) return JSON.stringify(drawflow);

return drawflow;
};

reader.onload = ({ target }) => {
const handleOnLoadReader = ({ target }) => {
const workflow = JSON.parse(target.result);

if (workflow.includedWorkflows) {
Expand Down Expand Up @@ -52,7 +50,12 @@ export function importWorkflow() {
});
};

reader.readAsText(file);
files.forEach((file) => {
const reader = new FileReader();

reader.onload = handleOnLoadReader;
reader.readAsText(file);
});
})
.catch((error) => {
console.error(error);
Expand Down

0 comments on commit a122904

Please sign in to comment.