Skip to content

Commit

Permalink
Adjust uploads response expectations
Browse files Browse the repository at this point in the history
Resolves #2
  • Loading branch information
mybearworld committed Nov 7, 2024
1 parent a1553b3 commit 4520a7e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Fixed

- Adjust changes to Uploads response format (https://github.com/meower-media/uploads/issues/7)

### Deprecated

- Removed keys from Uploads response format (https://github.com/meower-media/uploads/issues/7)

## 1.7.1 - 2024-11-02

### Fixed
Expand Down
11 changes: 9 additions & 2 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ export class RoarBot {
* @throws If the API returns an error.
*/
async upload(file: Blob): Promise<UploadsAttachment> {
if (!this._token) {
if (!this._username || !this._token) {
throw new Error("The bot is not logged in.");
}
if (file.size > ATTACMHENT_MAX_SIZE) {
Expand All @@ -454,7 +454,14 @@ export class RoarBot {
})
).json()
);
return response;
return {
...response,
bucket: "attachments",
claimed: false,
hash: "",
uploaded_at: Math.floor(Date.now() / 1000),
uploaded_by: this._username,
};
}

/**
Expand Down
33 changes: 24 additions & 9 deletions types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,45 @@ export const UPDATE_POST_PACKET_SCHEMA = z.object({
export const DELETE_POST_PACKET_SCHEMA = z.object({
cmd: z.literal("delete_post"),
val: z.object({
post_id: z.string()
post_id: z.string(),
}),
});

/** An attachment as returned from the uploading API. */
export type UploadsAttachment = {
/**
* @deprecated This only exists for backwards compatibility. Meower has
* removed this key.
*/
bucket: string;
/**
* @deprecated This only exists for backwards compatibility. Meower has
* removed this key.
*/
claimed: boolean;
filename: string;
/**
* @deprecated This only exists for backwards compatibility. Meower has
* removed this key.
*/
hash: string;
id: string;
/**
* @deprecated This only exists for backwards compatibility. Meower has
* removed this key.
*/
uploaded_at: number;
/**
* @deprecated This only exists for backwards compatibility. Meower has
* removed this key.
*/
uploaded_by: string;
};
export const UPLOADS_ATTACHMENT_SCHEMA: z.ZodType<UploadsAttachment> = z.object(
export const UPLOADS_ATTACHMENT_SCHEMA = z.object(
{
bucket: z.string(),
claimed: z.boolean(),
filename: z.string(),
hash: z.string(),
id: z.string(),
uploaded_at: z.number(),
uploaded_by: z.string(),
},
}
);

/** A user from the API. */
Expand Down Expand Up @@ -143,5 +158,5 @@ export const USER_SCHEMA: z.ZodType<User> = z.object({
});

export const API_USER_SCHEMA = USER_SCHEMA.and(
z.object({ error: z.literal(false) }),
z.object({ error: z.literal(false) })
).or(z.object({ error: z.literal(true), type: z.string() }));

0 comments on commit 4520a7e

Please sign in to comment.