Skip to content

Commit da9bd18

Browse files
author
Danil Rosomakha
committed
Add uploadImageStream method & Fix updateImage method
1 parent be8810a commit da9bd18

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

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: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import FormData from 'form-data';
2+
import { ReadStream } from 'node:fs';
23
import type { AGallery } from '../../types/gallery';
34
import type { AnImage } from '../../types/story';
45
import { type ArcAPIOptions, ArcAbstractAPI } from '../abstract-api';
@@ -23,6 +24,26 @@ export class ArcProtoCenter extends ArcAbstractAPI {
2324
return data;
2425
}
2526

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

5172
async updateImage(imageId: string, photoDto: AnImage) {
52-
const { data } = await this.client.put<AnImage>(`/v2/photos/${imageId}`, { data: photoDto });
73+
const { data } = await this.client.put<AnImage>(`/v2/photos/${imageId}`, photoDto);
5374
return data;
5475
}
5576
}

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)