Skip to content

Commit

Permalink
Merge pull request #204 from KenEucker/develop
Browse files Browse the repository at this point in the history
2.2.0
  • Loading branch information
KenEucker authored Apr 21, 2022
2 parents 7d3d295 + 8f2765f commit ca82d8d
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.ts linguist-detectable=true
*.* linguist-detectable=false
9 changes: 0 additions & 9 deletions .github/dependabot.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const response = await client.upload({
image: createReadStream('/home/kai/dank-meme.jpg'),
type: 'stream',
});
response.data.forEach((r) => console.log(r.link));
console.log(response.data);
```

If you want to provide metadata, such as a title, description, etc., then pass an object instead of a string:
Expand Down
6 changes: 4 additions & 2 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ const run = async (client) => {
const imageStream = createReadStream(join(__dirname, 'small.jpg'));
const videoStream = createReadStream(join(__dirname, 'small.mp4'));

await client.upload({ album, image: imageStream, type: 'stream' }).then(console.log);
await client.upload({ album, image: videoStream, type: 'stream' }).then(console.log);
await client.createAlbum('test').then(console.log)

// await client.upload({ album, image: imageStream, type: 'stream' }).then(console.log);
// await client.upload({ album, image: videoStream, type: 'stream' }).then(console.log);

}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Ken Eucker <[email protected]>",
"name": "imgur",
"description": "Unofficial JavaScript library for Imgur",
"version": "2.1.4",
"version": "2.2.0",
"homepage": "https://github.com/keneucker/imgur",
"license": "AGPL-3.0-or-later",
"keywords": [
Expand Down
5 changes: 5 additions & 0 deletions src/album/createAlbum.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('test imgur album creation', () => {
test('no tests ready because issues', async () => {
expect(true).toBe(true);
});
});
28 changes: 28 additions & 0 deletions src/album/createAlbum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ImgurClient } from '../client';
import { ALBUM_ENDPOINT } from '../common/endpoints';
import { ImgurApiResponse, AlbumData } from '../common/types';
import { createForm, getImgurApiResponseFromResponse } from '../common/utils';

export async function createAlbum(
client: ImgurClient,
title?: string,
description?: string
): Promise<ImgurApiResponse<AlbumData>> {
const form = createForm({ title, description });
const response = await client
.request({
url: ALBUM_ENDPOINT,
headers: form.getHeaders(),
method: 'POST',
data: form,
})
.catch((e) => e.response);

if (response.data?.success && response.data?.data) {
response.data.data.title = title;
response.data.data.description = description;
}
return getImgurApiResponseFromResponse(
response
) as ImgurApiResponse<AlbumData>;
}
1 change: 1 addition & 0 deletions src/album/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './createAlbum';
export * from './getAlbum';
9 changes: 8 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
searchGallery,
SearchGalleryOptions,
} from './gallery';
import { getAlbum } from './album';
import { getAlbum, createAlbum } from './album';
import { getAccount, getAlbums, getAlbumsIds } from './account';
import { IMGUR_API_PREFIX } from './common/endpoints';
import {
Expand Down Expand Up @@ -108,6 +108,13 @@ export class ImgurClient extends EventEmitter {
return getAlbums(this, account, page);
}

createAlbum(
title?: string,
description?: string
): Promise<ImgurApiResponse<AlbumData>> {
return createAlbum(this, title, description);
}

getAlbumsIds(
account: string,
page?: number
Expand Down
2 changes: 1 addition & 1 deletion src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function createForm(payload: string | Payload): FormData {
if (supportedUploadObjectTypes.indexOf(payload.type as string) !== -1) {
form.append(key, payload);
}
} else {
} else if (value) {
form.append(key, value);
}
}
Expand Down

0 comments on commit ca82d8d

Please sign in to comment.