@threadbase-sh/streamer 1.52.6 → 1.53.1

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.
package/dist/index.cjs CHANGED
@@ -4171,21 +4171,16 @@ var authMiddleware = (deps) => async (c, next) => {
4171
4171
  await next();
4172
4172
  return;
4173
4173
  }
4174
- if (deps.localNoAuth) {
4175
- if (isLocalRequest(remoteAddr)) {
4176
- await next();
4177
- return;
4178
- }
4179
- }
4174
+ const loopbackOwner = deps.localNoAuth && isLocalRequest(remoteAddr);
4180
4175
  const authorization = c.req.header("authorization");
4181
4176
  const bearer = authorization?.startsWith("Bearer ") ? authorization.slice(7) : void 0;
4182
4177
  const queryKey = c.req.query("key") ?? void 0;
4183
4178
  const presented = bearer ?? queryKey;
4184
- if (!presented) {
4179
+ if (!presented && !loopbackOwner) {
4185
4180
  return c.json({ error: "Unauthorized" }, 401);
4186
4181
  }
4187
4182
  let principal = null;
4188
- const device = deps.devicesRepo()?.authenticate(presented) ?? null;
4183
+ const device = presented ? deps.devicesRepo()?.authenticate(presented) ?? null : null;
4189
4184
  if (device) {
4190
4185
  principal = {
4191
4186
  kind: "device",
@@ -4196,7 +4191,9 @@ var authMiddleware = (deps) => async (c, next) => {
4196
4191
  deps.devicesRepo()?.touch(device.device_id);
4197
4192
  } catch {
4198
4193
  }
4199
- } else if (validateApiKey(presented, deps.apiKey)) {
4194
+ } else if (presented && validateApiKey(presented, deps.apiKey)) {
4195
+ principal = legacyPrincipal();
4196
+ } else if (loopbackOwner) {
4200
4197
  principal = legacyPrincipal();
4201
4198
  }
4202
4199
  if (!principal) {
@@ -14045,9 +14042,15 @@ function getSortValue(s, key) {
14045
14042
  case "projectName":
14046
14043
  return s.projectName;
14047
14044
  case "status":
14048
- return s.status;
14045
+ return statusSortValue(s);
14049
14046
  }
14050
14047
  }
14048
+ function statusSortValue(s) {
14049
+ const rank = s.status === "idle" ? 1 : 0;
14050
+ const activeAt = Date.parse(s.lastActivityAt ?? s.startedAt);
14051
+ const recency = String(1e15 - (Number.isNaN(activeAt) ? 0 : activeAt)).padStart(16, "0");
14052
+ return `${rank}:${recency}`;
14053
+ }
14051
14054
  function compareValues(a, b) {
14052
14055
  if (a === void 0 && b === void 0) return 0;
14053
14056
  if (a === void 0) return 1;