retold-remote 0.0.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.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/css/retold-remote.css +83 -0
  3. package/html/codejar.js +511 -0
  4. package/html/index.html +23 -0
  5. package/package.json +68 -0
  6. package/server.js +43 -0
  7. package/source/Pict-Application-RetoldRemote-Configuration.json +7 -0
  8. package/source/Pict-Application-RetoldRemote.js +622 -0
  9. package/source/Pict-RetoldRemote-Bundle.js +14 -0
  10. package/source/cli/RetoldRemote-CLI-Program.js +15 -0
  11. package/source/cli/RetoldRemote-CLI-Run.js +3 -0
  12. package/source/cli/RetoldRemote-Server-Setup.js +257 -0
  13. package/source/cli/commands/RetoldRemote-Command-Serve.js +87 -0
  14. package/source/providers/Pict-Provider-GalleryFilterSort.js +597 -0
  15. package/source/providers/Pict-Provider-GalleryNavigation.js +819 -0
  16. package/source/providers/Pict-Provider-RetoldRemote.js +273 -0
  17. package/source/providers/Pict-Provider-RetoldRemoteIcons.js +640 -0
  18. package/source/providers/Pict-Provider-RetoldRemoteTheme.js +879 -0
  19. package/source/server/RetoldRemote-MediaService.js +536 -0
  20. package/source/server/RetoldRemote-PathRegistry.js +121 -0
  21. package/source/server/RetoldRemote-ThumbnailCache.js +89 -0
  22. package/source/server/RetoldRemote-ToolDetector.js +78 -0
  23. package/source/views/PictView-Remote-Gallery.js +1437 -0
  24. package/source/views/PictView-Remote-ImageViewer.js +363 -0
  25. package/source/views/PictView-Remote-Layout.js +420 -0
  26. package/source/views/PictView-Remote-MediaViewer.js +530 -0
  27. package/source/views/PictView-Remote-SettingsPanel.js +318 -0
  28. package/source/views/PictView-Remote-TopBar.js +206 -0
  29. package/web-application/codejar.js +511 -0
  30. package/web-application/css/retold-remote.css +83 -0
  31. package/web-application/index.html +23 -0
  32. package/web-application/js/pict.min.js +12 -0
  33. package/web-application/js/pict.min.js.map +1 -0
  34. package/web-application/retold-remote.compatible.js +5764 -0
  35. package/web-application/retold-remote.compatible.js.map +1 -0
  36. package/web-application/retold-remote.compatible.min.js +120 -0
  37. package/web-application/retold-remote.compatible.min.js.map +1 -0
  38. package/web-application/retold-remote.js +5763 -0
  39. package/web-application/retold-remote.js.map +1 -0
  40. package/web-application/retold-remote.min.js +120 -0
  41. package/web-application/retold-remote.min.js.map +1 -0
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Retold Remote -- Filesystem Thumbnail Cache
3
+ *
4
+ * Caches generated thumbnails as files in a hidden directory under the
5
+ * content root. Cache keys are derived from the file path, modification
6
+ * time, and requested dimensions so that stale entries are automatically
7
+ * invalidated when the source file changes.
8
+ */
9
+ const libFs = require('fs');
10
+ const libPath = require('path');
11
+ const libCrypto = require('crypto');
12
+
13
+ class ThumbnailCache
14
+ {
15
+ /**
16
+ * @param {string} pCachePath - Absolute path to the cache directory
17
+ */
18
+ constructor(pCachePath)
19
+ {
20
+ this._cachePath = pCachePath;
21
+
22
+ // Ensure the cache directory exists
23
+ if (!libFs.existsSync(this._cachePath))
24
+ {
25
+ libFs.mkdirSync(this._cachePath, { recursive: true });
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Build a cache key from the source file path, its mtime, and the
31
+ * requested thumbnail dimensions.
32
+ *
33
+ * @param {string} pFilePath - Relative path to the source file
34
+ * @param {number} pMtime - Source file mtime (ms since epoch)
35
+ * @param {number} pWidth - Thumbnail width
36
+ * @param {number} pHeight - Thumbnail height
37
+ * @returns {string} A hex hash suitable for use as a filename
38
+ */
39
+ buildKey(pFilePath, pMtime, pWidth, pHeight)
40
+ {
41
+ let tmpInput = `${pFilePath}:${pMtime}:${pWidth}x${pHeight}`;
42
+ return libCrypto.createHash('sha256').update(tmpInput).digest('hex');
43
+ }
44
+
45
+ /**
46
+ * Return the absolute path to a cached thumbnail, or null if no
47
+ * cached entry exists.
48
+ *
49
+ * @param {string} pKey - The cache key (from buildKey)
50
+ * @param {string} pFormat - File extension (e.g. 'webp', 'jpg')
51
+ * @returns {string|null}
52
+ */
53
+ get(pKey, pFormat)
54
+ {
55
+ let tmpPath = libPath.join(this._cachePath, `${pKey}.${pFormat || 'webp'}`);
56
+ if (libFs.existsSync(tmpPath))
57
+ {
58
+ return tmpPath;
59
+ }
60
+ return null;
61
+ }
62
+
63
+ /**
64
+ * Write a thumbnail buffer to the cache.
65
+ *
66
+ * @param {string} pKey - The cache key
67
+ * @param {Buffer} pBuffer - The thumbnail image data
68
+ * @param {string} pFormat - File extension (e.g. 'webp', 'jpg')
69
+ * @returns {string} The absolute path to the cached file
70
+ */
71
+ put(pKey, pBuffer, pFormat)
72
+ {
73
+ let tmpPath = libPath.join(this._cachePath, `${pKey}.${pFormat || 'webp'}`);
74
+ libFs.writeFileSync(tmpPath, pBuffer);
75
+ return tmpPath;
76
+ }
77
+
78
+ /**
79
+ * Get the absolute path to the cache directory.
80
+ *
81
+ * @returns {string}
82
+ */
83
+ getCachePath()
84
+ {
85
+ return this._cachePath;
86
+ }
87
+ }
88
+
89
+ module.exports = ThumbnailCache;
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Retold Remote -- Server-Side Tool Detector
3
+ *
4
+ * Detects availability of media processing tools at server startup.
5
+ * Results are cached for the lifetime of the process.
6
+ */
7
+ const libChildProcess = require('child_process');
8
+
9
+ class ToolDetector
10
+ {
11
+ constructor()
12
+ {
13
+ this._capabilities = null;
14
+ }
15
+
16
+ /**
17
+ * Detect all available tools and return a capabilities object.
18
+ * Results are cached after the first call.
19
+ *
20
+ * @returns {object} { sharp, imagemagick, ffmpeg, ffprobe }
21
+ */
22
+ detect()
23
+ {
24
+ if (this._capabilities)
25
+ {
26
+ return this._capabilities;
27
+ }
28
+
29
+ this._capabilities =
30
+ {
31
+ sharp: this._detectSharp(),
32
+ imagemagick: this._detectCommand('identify --version'),
33
+ ffmpeg: this._detectCommand('ffmpeg -version'),
34
+ ffprobe: this._detectCommand('ffprobe -version')
35
+ };
36
+
37
+ return this._capabilities;
38
+ }
39
+
40
+ /**
41
+ * Check if the sharp module is available.
42
+ *
43
+ * @returns {boolean}
44
+ */
45
+ _detectSharp()
46
+ {
47
+ try
48
+ {
49
+ require('sharp');
50
+ return true;
51
+ }
52
+ catch (pError)
53
+ {
54
+ return false;
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Check if a command-line tool is available by running it.
60
+ *
61
+ * @param {string} pCommand - The command to test (e.g. 'ffmpeg -version')
62
+ * @returns {boolean}
63
+ */
64
+ _detectCommand(pCommand)
65
+ {
66
+ try
67
+ {
68
+ libChildProcess.execSync(pCommand, { stdio: 'ignore', timeout: 5000 });
69
+ return true;
70
+ }
71
+ catch (pError)
72
+ {
73
+ return false;
74
+ }
75
+ }
76
+ }
77
+
78
+ module.exports = ToolDetector;