opencode-gpt-imagegen 1.0.1 → 1.0.2

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 (2) hide show
  1. package/dist/index.js +16 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -126,9 +126,24 @@ function buildSavedMessage(savedPath, requestedPath, size) {
126
126
  const versionNote = savedPath !== requestedPath ? ` (the requested path ${requestedPath} already existed; the new image was versioned to avoid overwriting it)` : "";
127
127
  return `Generated image saved to ${savedPath}${versionNote}. The image is ${size.width}x${size.height} pixels.`;
128
128
  }
129
+ async function isDirectory(p) {
130
+ try {
131
+ return (await fs3.stat(p)).isDirectory();
132
+ } catch {
133
+ return false;
134
+ }
135
+ }
136
+ async function ensureDir(dir) {
137
+ try {
138
+ await fs3.mkdir(dir, { recursive: true });
139
+ } catch (e) {
140
+ if (e.code !== "EEXIST" || !await isDirectory(dir))
141
+ throw e;
142
+ }
143
+ }
129
144
  async function saveGeneratedImage(out, ctxDir, base64) {
130
145
  const requestedPath = path3.isAbsolute(out) ? out : path3.resolve(ctxDir, out);
131
- await fs3.mkdir(path3.dirname(requestedPath), { recursive: true });
146
+ await ensureDir(path3.dirname(requestedPath));
132
147
  const savedPath = await pickNonOverwritePath(requestedPath);
133
148
  const png = Buffer.from(base64, "base64");
134
149
  await fs3.writeFile(savedPath, png);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-gpt-imagegen",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "OpenCode plugin for GPT Image 2 generation through your ChatGPT subscription, with reference images and safe PNG output.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",