Unverified Commit 63088327 authored by chayleaf's avatar chayleaf
Browse files

scanservjs: init at 2.27.1

This adds scanservjs (a web UI for SANE scanners) package.

https://github.com/sbs20/scanservjs/
parent dd51f523
Loading
Loading
Loading
Loading
+64 −0
Original line number Diff line number Diff line
diff --git a/packages/server/src/api.js b/packages/server/src/api.js
index bd43842..71ce7c9 100644
--- a/packages/server/src/api.js
+++ b/packages/server/src/api.js
@@ -105,7 +105,7 @@ module.exports = new class Api {
     }
 
     // If not then it's possible the default image is not quite the correct aspect ratio
-    const buffer = FileInfo.create(`${config.previewDirectory}/default.jpg`).toBuffer();
+    const buffer = FileInfo.create('NIX_OUT_PLACEHOLDER/lib/node_modules/scanservjs-api/data/preview/default.jpg').toBuffer();
 
     try {
       // We need to know the correct aspect ratio from the device
diff --git a/packages/server/src/application.js b/packages/server/src/application.js
index 2771036..0c2a4c0 100644
--- a/packages/server/src/application.js
+++ b/packages/server/src/application.js
@@ -26,7 +26,7 @@ module.exports = new class Application {
 
   userOptions() {
     if (this._userOptions === null) {
-      this._userOptions = new UserOptions('../../config/config.local.js');
+      this._userOptions = new UserOptions(process.env.NIX_SCANSERVJS_CONFIG_PATH);
     }
     return this._userOptions;
   }
diff --git a/packages/server/src/classes/user-options.js b/packages/server/src/classes/user-options.js
index f129e3c..c71e754 100644
--- a/packages/server/src/classes/user-options.js
+++ b/packages/server/src/classes/user-options.js
@@ -4,7 +4,7 @@ const path = require('path');
 module.exports = class UserOptions {
   constructor(localConfigPath) {
     if (localConfigPath) {
-      const localPath = path.join(__dirname, localConfigPath);
+      const localPath = localConfigPath;
       if (fs.existsSync(localPath)) {
         this.local = require(localPath);
       }
diff --git a/packages/server/src/configure.js b/packages/server/src/configure.js
index c9e5ed8..484949c 100644
--- a/packages/server/src/configure.js
+++ b/packages/server/src/configure.js
@@ -71,6 +71,7 @@ function initialize(rootPath) {
 
   try {
     fs.mkdirSync(config.outputDirectory, { recursive: true });
+    fs.mkdirSync(config.previewDirectory, { recursive: true });
     fs.mkdirSync(config.tempDirectory, { recursive: true });
   } catch (exception) {
     log.warn(`Error ensuring output and temp directories exist: ${exception}`);
diff --git a/packages/server/src/server.js b/packages/server/src/server.js
index e1a9fb0..3d58d37 100644
--- a/packages/server/src/server.js
+++ b/packages/server/src/server.js
@@ -5,7 +5,7 @@ const configure = require('./configure');
 const config = application.config();
 const app = express();
 
-app.use(express.static('client'));
+app.use(express.static('@client@'));
 
 configure(app);
 
+93 −0
Original line number Diff line number Diff line
{
  lib,
  fetchFromGitHub,
  buildNpmPackage,
  fetchNpmDeps,
  nodejs,
  substituteAll,
}:

let
  version = "2.27.1";
  src = fetchFromGitHub {
    owner = "sbs20";
    repo = "scanservjs";
    # rev = "v${version}";
    # 2.27.1 doesn't have a tag
    rev = "b15adc6f97fb152fd9819371bb1a9b8118baf55b";
    hash = "sha256-ne9fEF/eurWPXzmJQzBn5jiy+JgxMWiCXsOdmu2fj6E=";
  };

  depsHashes = {
    server = "sha256-M8t+TrE+ntZaI9X7hEel94bz34DPtW32n0KKMSoCfIs=";
    client = "sha256-C31WBYE8ba0t4mfKFAuYWrCZtSdN7tQIYmCflDRKuBM=";
  };

  serverDepsForClient = fetchNpmDeps {
    inherit src nodejs;
    sourceRoot = "${src.name}/packages/server";
    name = "scanservjs";
    hash = depsHashes.server or lib.fakeHash;
  };

  # static client files
  client = buildNpmPackage {
    pname = "scanservjs-client";
    inherit version src nodejs;

    sourceRoot = "${src.name}/packages/client";
    npmDepsHash = depsHashes.client or lib.fakeHash;

    preBuild = ''
      cd ../server
      chmod +w package-lock.json . /build/source/
      npmDeps=${serverDepsForClient} npmConfigHook
      cd ../client
    '';

    env.NODE_OPTIONS = "--openssl-legacy-provider";

    dontNpmInstall = true;
    installPhase = ''
      mv /build/source/dist/client $out
    '';
  };

in
buildNpmPackage {
  pname = "scanservjs";
  inherit version src nodejs;

  sourceRoot = "${src.name}/packages/server";
  npmDepsHash = depsHashes.server or lib.fakeHash;

  # can't use "patches" since they change the server deps' hash for building the client
  # (I don't want to maintain one more hash)
  preBuild = ''
    chmod +w /build/source
    patch -p3 <${
      substituteAll {
        src = ./decouple-from-source-tree.patch;
        inherit client;
      }
    }
    substituteInPlace src/api.js --replace 'NIX_OUT_PLACEHOLDER' "$out"
  '';

  postInstall = ''
    mkdir -p $out/bin
    makeWrapper ${lib.getExe nodejs} $out/bin/scanservjs \
      --set NODE_ENV production \
      --add-flags "'$out/lib/node_modules/scanservjs-api/src/server.js'"
  '';

  meta = {
    description = "SANE scanner nodejs web ui";
    longDescription = "scanservjs is a simple web-based UI for SANE which allows you to share a scanner on a network without the need for drivers or complicated installation.";
    homepage = "https://github.com/sbs20/scanservjs";
    license = lib.licenses.gpl2Only;
    mainProgram = "scanservjs";
    maintainers = with lib.maintainers; [ chayleaf ];
    platforms = lib.platforms.linux;
  };
}