Skip to content

Commit

Permalink
Merge pull request #176 from takker99:udd
Browse files Browse the repository at this point in the history
fix(deno-udd): Update Deno dependencies
  • Loading branch information
takker99 committed Jul 14, 2024
2 parents 96dbcc9 + c4f5b6e commit 063961a
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 145 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/udd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
- name: Update dependencies
run: >
deno run --allow-net --allow-read --allow-write=deps/
--allow-run=deno https://deno.land/x/udd@0.7.2/main.ts deps/*.ts
--test="deno test --allow-read --allow-write"
--allow-run=deno https://deno.land/x/udd@0.8.2/main.ts deps/*.ts
--test="deno test --allow-read"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
Expand Down
5 changes: 3 additions & 2 deletions deps/scrapbox-rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export type {
NotPrivilegeError,
Page,
PageList,
PageSnapshot,
PageSnapshotList,
PageSnapshotResult,
ProjectId,
ProjectResponse,
ProjectSearchResult,
Expand All @@ -25,4 +26,4 @@ export type {
SessionError,
Snapshot,
TweetInfo,
} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.7.1/rest.ts";
} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/rest.ts";
4 changes: 2 additions & 2 deletions deps/scrapbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ export type {
BaseLine,
Line,
Scrapbox,
} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.7.1/userscript.ts";
} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/userscript.ts";
export type {
BaseStore,
} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.7.1/baseStore.ts";
} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/baseStore.ts";
export * from "https://esm.sh/@progfay/scrapbox-parser@9.0.0";
138 changes: 0 additions & 138 deletions rest/getSnapshots.ts

This file was deleted.

2 changes: 1 addition & 1 deletion rest/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export * from "./project.ts";
export * from "./profile.ts";
export * from "./replaceLinks.ts";
export * from "./page-data.ts";
export * from "./getSnapshots.ts";
export * from "./snapshot.ts";
export * from "./link.ts";
export * from "./search.ts";
export * from "./getWebPageTitle.ts";
Expand Down
93 changes: 93 additions & 0 deletions rest/snapshot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import type {
ErrorLike,
NotFoundError,
NotLoggedInError,
NotMemberError,
PageSnapshotList,
PageSnapshotResult,
} from "../deps/scrapbox-rest.ts";
import { cookie } from "./auth.ts";
import { BaseOptions, Result, setDefaults } from "./util.ts";
import { makeError } from "./error.ts";

/** 不正な`timestampId`を渡されたときに発生するエラー */
export interface InvalidPageSnapshotIdError extends ErrorLike {
name: "InvalidPageSnapshotIdError";
}

/** get a page snapshot
*
* @param options connect.sid etc.
*/
export const getSnapshot = async (
project: string,
pageId: string,
timestampId: string,
options?: BaseOptions,
): Promise<
Result<
PageSnapshotResult,
| NotFoundError
| NotLoggedInError
| NotMemberError
| InvalidPageSnapshotIdError
>
> => {
const { sid, hostName, fetch } = setDefaults(options ?? {});

const req = new Request(
`https://${hostName}/api/page-snapshots/${project}/${pageId}/${timestampId}`,
sid ? { headers: { Cookie: cookie(sid) } } : undefined,
);

const res = await fetch(req);

if (!res.ok) {
if (res.status === 422) {
return {
ok: false,
value: {
name: "InvalidPageSnapshotIdError",
message: await res.text(),
},
};
}
return makeError<NotFoundError | NotLoggedInError | NotMemberError>(res);
}

const value = (await res.json()) as PageSnapshotResult;
return { ok: true, value };
};

/**
* Retrieves the timestamp IDs for a specific page in a project.
*
* @param project - The name of the project.
* @param pageId - The ID of the page.
* @param options - Optional configuration options.
* @returns A promise that resolves to a {@link Result} object containing the page snapshot list if successful,
* or an error if the request fails.
*/
export const getTimestampIds = async (
project: string,
pageId: string,
options?: BaseOptions,
): Promise<
Result<PageSnapshotList, NotFoundError | NotLoggedInError | NotMemberError>
> => {
const { sid, hostName, fetch } = setDefaults(options ?? {});

const req = new Request(
`https://${hostName}/api/page-snapshots/${project}/${pageId}`,
sid ? { headers: { Cookie: cookie(sid) } } : undefined,
);

const res = await fetch(req);

if (!res.ok) {
return makeError<NotFoundError | NotLoggedInError | NotMemberError>(res);
}

const value = (await res.json()) as PageSnapshotList;
return { ok: true, value };
};

0 comments on commit 063961a

Please sign in to comment.