Skip to content

Commit be48dbd

Browse files
authored
Merge pull request #19 from code-store-platform/feat/add-upload-image-api
Feat: Add uploadImageStream method & Fix updateImage method
2 parents be8810a + c461a11 commit be48dbd

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @code.store/arcxp-sdk-ts
22

3+
## 4.45.0
4+
5+
### Minor Changes
6+
7+
- Add uploadImageStream method & Fix updateImage method in ArcProtoCenter
8+
39
## 4.44.0
410

511
### Minor Changes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@code.store/arcxp-sdk-ts",
3-
"version": "4.44.0",
3+
"version": "4.45.0",
44
"description": "A strongly typed set of ArcXP API's and utilities reduce the amount of work required to develop with ArcXP, starting with reducing the boilerplate code you have to write.",
55
"type": "commonjs",
66
"main": "./dist/index.js",

src/api/photo-center/index.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import FormData from 'form-data';
2+
import path from 'node:path';
3+
import { type ReadStream } from 'node:fs';
24
import type { AGallery } from '../../types/gallery';
35
import type { AnImage } from '../../types/story';
46
import { type ArcAPIOptions, ArcAbstractAPI } from '../abstract-api';
@@ -23,6 +25,24 @@ export class ArcProtoCenter extends ArcAbstractAPI {
2325
return data;
2426
}
2527

28+
async uploadImageStream(
29+
readableStream: ReadStream,
30+
options?: { contentType?: string; filename?: string }
31+
): Promise<AnImage> {
32+
const form = new FormData();
33+
const contentType = options?.contentType ?? 'application/octet-stream';
34+
const filename = path.basename(String(options?.filename || readableStream.path || 'file.jpg'));
35+
36+
form.append('file', readableStream, {
37+
filename: filename,
38+
contentType,
39+
});
40+
41+
const { data } = await this.client.post('/v2/photos', form, { headers: form.getHeaders() });
42+
43+
return data;
44+
}
45+
2646
async deleteImage(imageId: string) {
2747
const { data } = await this.client.delete(`/v2/photos/${imageId}`);
2848
return data;
@@ -49,7 +69,7 @@ export class ArcProtoCenter extends ArcAbstractAPI {
4969
}
5070

5171
async updateImage(imageId: string, photoDto: AnImage) {
52-
const { data } = await this.client.put<AnImage>(`/v2/photos/${imageId}`, { data: photoDto });
72+
const { data } = await this.client.put<AnImage>(`/v2/photos/${imageId}`, photoDto);
5373
return data;
5474
}
5575
}

src/api/site/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ export type GetLinksResponse = {
3535
q_results: Link[];
3636
};
3737

38-
export type GetSectionParams ={
38+
export type GetSectionParams = {
3939
website: string;
4040
offset?: number;
4141
include_inactive?: boolean;
42-
}
42+
};

0 commit comments

Comments
 (0)