Skip to content

Commit

Permalink
feat: option to ignore certain paths/names and store them temporarily…
Browse files Browse the repository at this point in the history
… on disk instead
  • Loading branch information
Dwynr committed Sep 14, 2024
1 parent c54d66a commit e7afae8
Show file tree
Hide file tree
Showing 11 changed files with 487 additions and 73 deletions.
63 changes: 56 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@filen/webdav",
"version": "0.2.50",
"version": "0.2.51",
"description": "Filen WebDAV",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -38,6 +38,7 @@
"@types/fs-extra": "^11.0.4",
"@types/lodash": "^4.14.202",
"@types/mime-types": "^2.1.4",
"@types/picomatch": "^3.0.1",
"@types/uuid": "^10.0.0",
"@types/write-file-atomic": "^4.0.3",
"@types/xml2js": "^0.4.14",
Expand All @@ -58,8 +59,10 @@
"express": "^4.19.2",
"express-rate-limit": "^7.4.0",
"fs-extra": "^11.2.0",
"js-xxhash": "^4.0.0",
"mime-types": "^2.1.35",
"node-cache": "^5.1.2",
"picomatch": "^4.0.2",
"pino": "^9.4.0",
"rotating-file-stream": "^3.2.3",
"selfsigned": "^2.4.1",
Expand Down
80 changes: 74 additions & 6 deletions src/handlers/copy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { type Request, type Response } from "express"
import type Server from ".."
import Responses from "../responses"
import { removeLastSlash } from "../utils"
import { removeLastSlash, pathToTempDiskFileId } from "../utils"
import pathModule from "path"
import fs from "fs-extra"

/**
* Copy
Expand Down Expand Up @@ -103,11 +104,22 @@ export class Copy {
}

if (resource.isVirtual) {
if (overwrite && destinationResource && !destinationResource.isVirtual) {
await sdk.fs().unlink({
path: destinationResource.path,
permanent: true
})
if (overwrite && destinationResource) {
if (destinationResource.tempDiskId) {
await fs.rm(pathModule.join(this.server.tempDiskPath, destinationResource.tempDiskId), {
force: true,
maxRetries: 60 * 10,
recursive: true,
retryDelay: 100
})
}

if (!destinationResource.isVirtual) {
await sdk.fs().unlink({
path: destinationResource.path,
permanent: true
})
}

this.server.getVirtualFilesForUser(req.username)[destination] = {
...resource,
Expand All @@ -133,6 +145,62 @@ export class Copy {
return
}

if (resource.tempDiskId) {
const destinationTempDiskFileId = pathToTempDiskFileId(destination, req.username)

if (overwrite && destinationResource) {
if (destinationResource.tempDiskId) {
await fs.rm(pathModule.join(this.server.tempDiskPath, destinationResource.tempDiskId), {
force: true,
maxRetries: 60 * 10,
recursive: true,
retryDelay: 100
})
}

if (!destinationResource.isVirtual) {
await sdk.fs().unlink({
path: destinationResource.path,
permanent: true
})
}

await fs.copy(
pathModule.join(this.server.tempDiskPath, resource.tempDiskId),
pathModule.join(this.server.tempDiskPath, destinationTempDiskFileId)
)

this.server.getTempDiskFilesForUser(req.username)[destination] = {
...resource,
url: destination,
path: destination,
name: pathModule.posix.basename(destination),
tempDiskId: destinationTempDiskFileId
}

await Responses.noContent(res)

return
}

await fs.copy(
pathModule.join(this.server.tempDiskPath, resource.tempDiskId),
pathModule.join(this.server.tempDiskPath, destinationTempDiskFileId)
)

this.server.getTempDiskFilesForUser(req.username)[destination] = {
...resource,
url: destination,
path: destination,
name: pathModule.posix.basename(destination),
tempDiskId: destinationTempDiskFileId
}

await Responses.created(res)

return
}

if (overwrite && destinationResource) {
await sdk.fs().unlink({
path: destinationResource.path,
Expand Down
17 changes: 17 additions & 0 deletions src/handlers/delete.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { type Request, type Response } from "express"
import type Server from ".."
import Responses from "../responses"
import fs from "fs-extra"
import pathModule from "path"

/**
* Delete
Expand Down Expand Up @@ -48,6 +50,21 @@ export class Delete {
return
}

if (resource.tempDiskId) {
await fs.rm(pathModule.join(this.server.tempDiskPath, resource.tempDiskId), {
force: true,
maxRetries: 60 * 10,
recursive: true,
retryDelay: 100
})

delete this.server.getTempDiskFilesForUser(req.username)[resource.path]

await Responses.ok(res)

return
}

const sdk = this.server.getSDKForUser(req.username)

if (!sdk) {
Expand Down
Loading

0 comments on commit e7afae8

Please sign in to comment.