Skip to content

Usenet streaming with a WebDAV server and a SABnzbd-compatible API

C#

Fix Kodi scrubbing issues (#248)

Anonymous user0b37e10332ee
diff --git a/backend/Api/Controllers/GetWebdavItem/GetWebdavItemController.cs b/backend/Api/Controllers/GetWebdavItem/GetWebdavItemController.cs
index cdb5a515..16ee69cd 100644
--- a/backend/Api/Controllers/GetWebdavItem/GetWebdavItemController.cs
+++ b/backend/Api/Controllers/GetWebdavItem/GetWebdavItemController.cs
@@ -23,6 +23,9 @@ public class ListWebdavDirectoryController(DatabaseStore store, ConfigManager co
if (item is null) throw new BadHttpRequestException("The file does not exist.");
if (item is IStoreCollection) throw new BadHttpRequestException("The file does not exist.");
+ // disable compression to keep Content-Length intact for clients that need seeking
+ Response.Headers["Content-Encoding"] = "identity";
+
// handle par2 preview
if (Path.GetExtension(item.Name).ToLower() == ".par2" && configManager.IsPreviewPar2FilesEnabled())
return await GetPar2PreviewStream(item).ConfigureAwait(false);
@@ -33,6 +36,8 @@ public class ListWebdavDirectoryController(DatabaseStore store, ConfigManager co
// set the content-typ header
Response.Headers["Content-Type"] = GetContentType(item.Name);
+ // disable compression to keep Content-Length intact for clients that need seeking
+ Response.Headers["Content-Encoding"] = "identity";
Response.Headers["Accept-Ranges"] = "bytes";
if (request.RangeStart is not null)
@@ -74,6 +79,22 @@ public class ListWebdavDirectoryController(DatabaseStore store, ConfigManager co
}
}
+ [HttpHead]
+ public async Task HandleHeadRequest()
+ {
+ try
+ {
+ HttpContext.Items["configManager"] = configManager;
+ var request = new GetWebdavItemRequest(HttpContext);
+ await using var response = await GetWebdavItem(request).ConfigureAwait(false);
+ // HEAD: headers already set, body omitted
+ }
+ catch (UnauthorizedAccessException)
+ {
+ Response.StatusCode = 401;
+ }
+ }
+
private static string GetContentType(string item)
{
if (item == "README") return "text/plain";
diff --git a/frontend/server.ts b/frontend/server.ts
index dcdbf550..9c2cc412 100644
--- a/frontend/server.ts
+++ b/frontend/server.ts
@@ -11,7 +11,25 @@ const PORT = Number.parseInt(process.env.PORT || "3000");
// Initialize the express app
const app = express();
-app.use(compression());
+app.use(
+ compression({
+ // Don't compress proxied WebDAV/media/API responses; keep Content-Length intact for seek
+ filter: (req, res) => {
+ const path = req.path || "";
+ if (
+ path.startsWith("/view") ||
+ path.startsWith("/.ids") ||
+ path.startsWith("/nzbs") ||
+ path.startsWith("/content") ||
+ path.startsWith("/completed-symlinks") ||
+ path.startsWith("/api")
+ ) {
+ return false;
+ }
+ return compression.filter(req, res);
+ },
+ }),
+);
app.disable("x-powered-by");
// Initialize the websocket server as soon as both it and the server-module are ready