offline-cloudinary 2.1.0 → 2.1.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/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.1.1] - 2026-01-15
9
+
10
+ ### Fixed
11
+
12
+ - Fixed file path resolution in `viewImage` controller to properly use cached file paths
13
+ - Ensured in-memory cache is explicitly loaded from disk on server startup via `initialise()` call
14
+
8
15
  ## [2.1.0] - 2025-12-18
9
16
 
10
17
  ### Added
@@ -87,7 +94,7 @@ const result = await offlineCloudinary.upload("./photo.jpg");
87
94
  const result = await offlineCloudinary.upload("./photo.jpg");
88
95
  // result.public_id is now a UUID like "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
89
96
  // result.url is "http://localhost:3000/file/a1b2c3d4-e5f6-7890-abcd-ef1234567890"
90
- // result.secure_url is the actual file path
97
+ // result.secure_url is "http://localhost:3000/file/a1b2c3d4-e5f6-7890-abcd-ef1234567890"
91
98
  ```
92
99
 
93
100
  #### 4. Update destroy calls
package/index.js CHANGED
@@ -9,10 +9,11 @@ app.use(cors());
9
9
 
10
10
  app.use("/file", fileRoutes);
11
11
 
12
- const startEmulator = () => {
12
+ const startEmulator = async() => {
13
13
  const portNumber = process.env.CLOUDINARY_OFFLINE_PORT;
14
14
  if (!portNumber)
15
15
  throw new Error("Please set CLOUDINARY_OFFLINE_PORT in your .env file");
16
+ await offlineCloudinary.initialise()
16
17
  app.listen(portNumber, () =>{
17
18
  console.log("Offline Cloudinary running on port", portNumber)
18
19
  process.on("SIGINT", async()=>{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "offline-cloudinary",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "An offline Cloudinary-like file manager with HTTP server emulator for local uploads, deletions, and testing without internet access.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -1,10 +1,8 @@
1
1
  import offlineCloudinary from '../utils/offline-cloudinary.js';
2
- import fs from 'fs/promises';
3
2
 
4
3
  export const viewImage = async(req, res)=>{
5
4
  const uploadId = req.params.id
6
- const data = await fs.readFile("uploads.json", "utf-8")
7
- const mappings = JSON.parse(data)
5
+ const mappings = offlineCloudinary.mappingsInMemory
8
6
  res.setHeader("Content-Disposition", "inline")
9
- return res.sendFile(`${offlineCloudinary.rootPath}/${mappings[uploadId]}`)
7
+ return res.sendFile(`${mappings[uploadId]}`)
10
8
  }
@@ -40,7 +40,6 @@ class OfflineCloudinary {
40
40
  * @returns Cloudinary-like response
41
41
  */
42
42
  async upload(tempFilePath, options = {}) {
43
- await this.initialise();
44
43
  const portNumber = process.env.CLOUDINARY_OFFLINE_PORT || 3500;
45
44
  await fs.access(tempFilePath).catch(() => {
46
45
  throw new Error(`File not found: ${tempFilePath}`);
@@ -101,7 +100,6 @@ class OfflineCloudinary {
101
100
  * @returns {object} { result: "ok" } if deleted or { result: "not found" }
102
101
  */
103
102
  async destroy(public_id) {
104
- await this.initialise();
105
103
  const uploadId = public_id;
106
104
  const filePath = this.mappingsInMemory[uploadId];
107
105
  if (filePath) {
@@ -1 +0,0 @@
1
- {}