Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
catch the lastest dev (#186)
Browse files Browse the repository at this point in the history
* Add endpoint of upload status (#181)

* api key update (#185)

---------

Co-authored-by: liulw2022 <[email protected]>
Co-authored-by: a-thansen <[email protected]>
  • Loading branch information
3 people authored Dec 18, 2023
1 parent 71a3699 commit 98e8ad0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
10 changes: 10 additions & 0 deletions backend/src/upload/file.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,19 @@ export class FileProcessor {
fs.mkdirSync(tempUnzipPath, { recursive: true });
}

// Start the unzip process with a progress of 0%
await job.progress(0);

// Stream the zip file and extract to the temporary directory

fs.createReadStream(filePath)
.pipe(unzip.Extract({ path: tempUnzipPath }))
.on('error', (error) => {
console.error(`Error unzipping file: ${filePath}`, error);
})
.on('close', async () => {
await this.handleUnzippedContent(tempUnzipPath, filePath);
await job.progress(60);
});
} catch (error) {
console.error(`Error processing file: ${job.data.filePath}`, error);
Expand Down Expand Up @@ -121,6 +126,8 @@ export class FileProcessor {

// TODO(Seb-sti1): (when rest working) add valhalla here

await job.progress(65);

// Upload all data and images to the database
await Promise.all([
...data.map(async (data) => {
Expand All @@ -145,6 +152,7 @@ export class FileProcessor {
);
}),
]);
await job.progress(99);
}

// Delete the unzipped file
Expand All @@ -161,6 +169,8 @@ export class FileProcessor {
console.log(
`File processed successfully and imported into Database: ${filePath}`,
);
await job.progress(100);
console.log(`Job ${job.id} completed`);
} catch (error) {
console.error(`Error processing file: ${job.data.filePath}`, error);
}
Expand Down
22 changes: 22 additions & 0 deletions backend/src/upload/upload.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Post,
UploadedFile,
UseInterceptors,
Get,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { InjectQueue } from '@nestjs/bull';
Expand Down Expand Up @@ -79,4 +80,25 @@ export class UploadController {
};
}
}
@Get('status')
async getUploadStatus() {
const jobs = await this.fileQueue.getJobs([
'waiting',
'active',
'completed',
'failed',
]);
const jobStatus = await Promise.all(
jobs.map(async (job) => ({
id: job.id,
name: job.name,
timestamp: job.timestamp,
jobData: job.data,
status: await job.getState(),
progress: await job.progress(),
})),
);
console.log('Job Status:', jobStatus);
return jobStatus;
}
}
2 changes: 1 addition & 1 deletion frontend/src/Components/Map/Inputs/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface Props {
*/
const Search: React.FC<Props> = ({ onPlaceSelect }) => {
return (
<GeoapifyContext apiKey="bb524d9939ae497688b9b2dddc5cf0a2">
<GeoapifyContext apiKey="278562afd6274f1484c58a79d37c76af">
<GeoapifyGeocoderAutocomplete
placeholder="Enter address here"
type={'street'}
Expand Down

0 comments on commit 98e8ad0

Please sign in to comment.