Skip to content

Commit 8057043

Browse files
Sped up the upload process (#35)
* Sped up the upload process * Version increment
1 parent 2da3123 commit 8057043

3 files changed

Lines changed: 17 additions & 20 deletions

File tree

src-tauri/src/thing_api.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ use tauri_plugin_store::StoreExt;
1111
///
1212
/// The response from the WoWthing API.
1313
#[tauri::command]
14-
pub async fn submit_addon_data(app: tauri::AppHandle, contents: &str) -> Result<String, String> {
14+
pub async fn submit_addon_data(app: tauri::AppHandle, file_path: &str) -> Result<String, String> {
1515
let store = app.store_builder(".settings.dat").build().unwrap();
1616
let api_key = store.get("api-key").expect("No API key found in settings.");
17+
let contents = &std::fs::read_to_string(file_path).map_err(|e| e.to_string())?;
1718

1819
let mut form_data = HashMap::new();
1920
form_data.insert("apiKey", api_key.as_str().unwrap());
20-
form_data.insert("luaFile", contents);
21+
form_data.insert("luaFile", &contents);
2122

2223
let client = reqwest::Client::new();
2324
let response = client

src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
"productName": "Wowthing Sync",
4343
"mainBinaryName": "Wowthing Sync",
44-
"version": "1.0.4",
44+
"version": "1.0.5",
4545
"identifier": "com.calebsmithdev.wowthing-sync",
4646
"plugins": {
4747
"updater": {

src/composables/useFileUpload.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BaseDirectory, readDir, type ReadFileOptions, type DirEntry, readTextFileLines, type WatchEvent, type UnwatchFn } from '@tauri-apps/plugin-fs';
1+
import { BaseDirectory, readDir, type DirEntry, type WatchEvent, type UnwatchFn } from '@tauri-apps/plugin-fs';
22
import { watch } from '@tauri-apps/plugin-fs'
33
import relativeTime from 'dayjs/plugin/relativeTime'
44
import localizedFormat from 'dayjs/plugin/localizedFormat'
@@ -7,7 +7,8 @@ import { LAST_STARTED_DATE, LAST_UPDATED, PROGRAM_FOLDER } from '../constants';
77
import { getStorageItem, saveStorageItem } from '../utils/storage';
88
import { invoke } from '@tauri-apps/api/core';
99
import { join } from '@tauri-apps/api/path';
10-
import { info } from '@tauri-apps/plugin-log';
10+
import { error, info } from '@tauri-apps/plugin-log';
11+
import { platform } from '@tauri-apps/plugin-os';
1112

1213
export const useFileUpload = () => {
1314
dayjs.extend(relativeTime)
@@ -94,7 +95,12 @@ export const useFileUpload = () => {
9495
}
9596

9697
const isModifyAnyEvent = (event: WatchEvent): boolean => {
97-
return typeof event.type === 'object' && 'modify' in event.type && (event.type.modify.kind === 'any' || event.type.modify.kind === 'rename');
98+
const currentPlatform = platform();
99+
if(currentPlatform === 'macos') {
100+
return typeof event.type === 'object' && 'modify' in event.type && (event.type.modify.kind === 'any' || event.type.modify.kind === 'rename');
101+
} else {
102+
return typeof event.type === 'object' && 'modify' in event.type && event.type.modify.kind === 'any';
103+
}
98104
}
99105

100106
const handleUpload = async (force: boolean = false, event: WatchEvent = null) => {
@@ -108,6 +114,7 @@ export const useFileUpload = () => {
108114
if (event && !isModifyAnyEvent(event)) {
109115
return;
110116
}
117+
console.log({event})
111118

112119
isProcessing.value = true;
113120
await saveStorageItem<string>(LAST_STARTED_DATE, dayjs().format());
@@ -123,14 +130,13 @@ export const useFileUpload = () => {
123130

124131
for (const file of dedupedFiles) {
125132
info(`Uploading file: ${file} at file path: ${file}`);
126-
const contents = await readBigFile(file, { baseDir: BaseDirectory.Home });
127133

128134
try {
129-
const message = await invoke('submit_addon_data', { contents });
135+
const message = await invoke('submit_addon_data', { filePath: file });
130136
info(`Uploaded file: ${file}`);
131137
info(`API response from ${file}: ${message}`);
132-
} catch (error) {
133-
error(`File failed to upload! File: ${file}; Return: ${error}`);
138+
} catch (result) {
139+
error(`File failed to upload! File: ${file}; Return: ${result}`);
134140
await notifications.send({ title: 'Wowthing Sync', body: 'An error occurred while uploading. Please try again later.' });
135141
isProcessing.value = false;
136142
return; // Stop the rest of the loop from working
@@ -152,16 +158,6 @@ export const useFileUpload = () => {
152158
return unique;
153159
}
154160

155-
const readBigFile = async (filePath: string, options?: ReadFileOptions) => {
156-
const lines = await readTextFileLines(filePath, options);
157-
let fileData = '';
158-
for await (const line of lines) {
159-
fileData += line;
160-
}
161-
162-
return fileData;
163-
};
164-
165161
onMounted(() => {
166162
getLastUpdated();
167163

0 commit comments

Comments
 (0)