Skip to content

Commit

Permalink
Handle failed upload
Browse files Browse the repository at this point in the history
  • Loading branch information
myieye committed Nov 19, 2024
1 parent 0c117d6 commit 200a520
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
5 changes: 3 additions & 2 deletions frontend/viewer/src/lib/SyncConfig.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import {writable} from 'svelte/store';
import {type ServerStatus, useProjectsService} from './services/projects-service';
import {getContext} from 'svelte';
import {AppNotification} from './notifications/notifications';
const projectsService = useProjectsService();
let projectName = getContext<string>('project-name');
Expand Down Expand Up @@ -48,9 +49,9 @@
if (!targetProjectId) return;
uploading = true;
//todo if not logged in then login
await projectsService.uploadCrdtProject($projectServer, projectName, targetProjectId);
const success = await projectsService.uploadCrdtProject($projectServer, projectName, targetProjectId);
uploading = false;
isUploaded = true;
if (success) isUploaded = true;
}
</script>

Expand Down
26 changes: 19 additions & 7 deletions frontend/viewer/src/lib/services/projects-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,35 @@ export class ProjectService {
return {error: undefined};
}

async importFwDataProject(name: string) {
await fetch(`/api/import/fwdata/${name}`, {
async importFwDataProject(name: string): Promise<boolean> {
const r = await fetch(`/api/import/fwdata/${name}`, {
method: 'POST',
});
if (!r.ok) {
AppNotification.display(`Failed to import FieldWorks project ${name}: ${r.statusText} (${r.status})`, 'error', 'long');
console.error(`Failed to import FieldWorks project ${name}: ${r.statusText} (${r.status})`, r, await r.text())
}
return r.ok;
}

async downloadCrdtProject(project: Project) {
const r = await fetch(`/api/download/crdt/${project.serverAuthority}/${project.name}`, {method: 'POST'});
if (r.status !== 200) {
AppNotification.display(`Failed to download project, status code ${r.status}`, 'error');
console.error(`Failed to download project ${project.name}`, r)
if (!r.ok) {
AppNotification.display(`Failed to download project ${project.name}: ${r.statusText} (${r.status})`, 'error', 'long');
console.error(`Failed to download project ${project.name}: ${r.statusText} (${r.status})`, r, await r.text())
}
return r.ok;
}

async uploadCrdtProject(server: string, projectName: string, lexboxProjectId: string) {
await fetch(`/api/upload/crdt/${server}/${projectName}?lexboxProjectId=${lexboxProjectId}`, {method: 'POST'});
async uploadCrdtProject(server: string, projectName: string, lexboxProjectId: string): Promise<boolean> {
const r = await fetch(`/api/upload/crdt/${server}/${projectName}?lexboxProjectId=${lexboxProjectId}`, {method: 'POST'});
if (!r.ok) {
AppNotification.display(`Failed to upload project ${projectName}: ${r.statusText} (${r.status})`, 'error', 'long');
console.error(`Failed to upload project ${projectName}: ${r.statusText} (${r.status})`, r, await r.text())
}
return r.ok;
}

async getProjectServer(projectName: string): Promise<string|null> {
const projects = await this.fetchProjects();
//todo project server is always null from local projects`
Expand Down

0 comments on commit 200a520

Please sign in to comment.