@aj-archipelago/cortex 1.1.18 → 1.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,43 +29,61 @@ async function deleteFolder(requestId) {
29
29
  console.log(`Cleaned folder: ${targetFolder}`);
30
30
  }
31
31
 
32
- async function cleanupLocal() {
33
- try {
34
- // Read the directory
35
- const items = await fs.readdir(publicFolder);
32
+ async function cleanupLocal(urls=null) {
33
+ if(!urls){
34
+ const cleanedUrls = []; // initialize array for holding cleaned file URLs
35
+ try {
36
+ // Read the directory
37
+ const items = await fs.readdir(publicFolder);
36
38
 
37
- // Calculate the date that is x months ago
38
- const monthsAgo = new Date();
39
- monthsAgo.setMonth(monthsAgo.getMonth() - 1);
39
+ // Calculate the date that is x months ago
40
+ const monthsAgo = new Date();
41
+ monthsAgo.setMonth(monthsAgo.getMonth() - 1);
40
42
 
41
- // Iterate through the items
42
- for (const item of items) {
43
- const itemPath = join(publicFolder, item);
43
+ // Iterate through the items
44
+ for (const item of items) {
45
+ const itemPath = join(publicFolder, item);
44
46
 
45
- // Get the stats of the item
46
- const stats = await fs.stat(itemPath);
47
+ // Get the stats of the item
48
+ const stats = await fs.stat(itemPath);
47
49
 
48
- // Check if the item is a file or a directory
49
- const isDirectory = stats.isDirectory();
50
+ // Check if the item is a file or a directory
51
+ const isDirectory = stats.isDirectory();
50
52
 
51
- // Compare the last modified date with three months ago
52
- if (stats.mtime < monthsAgo) {
53
- if (isDirectory) {
54
- // If it's a directory, delete it recursively
55
- await fs.rm(itemPath, { recursive: true });
56
- console.log(`Cleaned directory: ${item}`);
57
- } else {
58
- // If it's a file, delete it
59
- await fs.unlink(itemPath);
60
- console.log(`Cleaned file: ${item}`);
53
+ // Compare the last modified date with three months ago
54
+ if (stats.mtime < monthsAgo) {
55
+ if (isDirectory) {
56
+ // If it's a directory, delete it recursively
57
+ await fs.rm(itemPath, { recursive: true });
58
+ console.log(`Cleaned directory: ${item}`);
59
+ } else {
60
+ // If it's a file, delete it
61
+ await fs.unlink(itemPath);
62
+ console.log(`Cleaned file: ${item}`);
63
+
64
+ // Add the URL of the cleaned file to cleanedUrls array
65
+ cleanedUrls.push(`http://${ipAddress}:${port}/files/${item}`);
66
+ }
61
67
  }
62
68
  }
69
+ } catch (error) {
70
+ console.error(`Error cleaning up files: ${error}`);
71
+ }
72
+ }else{
73
+ try{
74
+ for (const url of urls) {
75
+ const filename = url.split('/').pop();
76
+ const itemPath = join(publicFolder, filename);
77
+ await fs.unlink(itemPath);
78
+ }
79
+ }catch(error){
80
+ console.error(`Error cleaning up files: ${error}`);
63
81
  }
64
- } catch (error) {
65
- console.error(`Error cleaning up files: ${error}`);
66
82
  }
67
- }
68
83
 
84
+ // Return the array of cleaned file URLs
85
+ return cleanedUrls;
86
+ }
69
87
 
70
88
  export {
71
89
  moveFileToPublicFolder, deleteFolder, cleanupLocal