Skip to content

Commit 063961a

Browse files
authored
Merge pull request #176 from takker99:udd
fix(deno-udd): Update Deno dependencies
2 parents 96dbcc9 + c4f5b6e commit 063961a

File tree

6 files changed

+101
-145
lines changed

6 files changed

+101
-145
lines changed

.github/workflows/udd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ jobs:
1616
- name: Update dependencies
1717
run: >
1818
deno run --allow-net --allow-read --allow-write=deps/
19-
--allow-run=deno https://deno.land/x/udd@0.7.2/main.ts deps/*.ts
20-
--test="deno test --allow-read --allow-write"
19+
--allow-run=deno https://deno.land/x/udd@0.8.2/main.ts deps/*.ts
20+
--test="deno test --allow-read"
2121
- name: Create Pull Request
2222
uses: peter-evans/create-pull-request@v3
2323
with:

deps/scrapbox-rest.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export type {
1616
NotPrivilegeError,
1717
Page,
1818
PageList,
19-
PageSnapshot,
19+
PageSnapshotList,
20+
PageSnapshotResult,
2021
ProjectId,
2122
ProjectResponse,
2223
ProjectSearchResult,
@@ -25,4 +26,4 @@ export type {
2526
SessionError,
2627
Snapshot,
2728
TweetInfo,
28-
} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.7.1/rest.ts";
29+
} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/rest.ts";

deps/scrapbox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ export type {
22
BaseLine,
33
Line,
44
Scrapbox,
5-
} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.7.1/userscript.ts";
5+
} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/userscript.ts";
66
export type {
77
BaseStore,
8-
} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.7.1/baseStore.ts";
8+
} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/baseStore.ts";
99
export * from "https://esm.sh/@progfay/[email protected]";

rest/getSnapshots.ts

Lines changed: 0 additions & 138 deletions
This file was deleted.

rest/mod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export * from "./project.ts";
44
export * from "./profile.ts";
55
export * from "./replaceLinks.ts";
66
export * from "./page-data.ts";
7-
export * from "./getSnapshots.ts";
7+
export * from "./snapshot.ts";
88
export * from "./link.ts";
99
export * from "./search.ts";
1010
export * from "./getWebPageTitle.ts";

rest/snapshot.ts

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import type {
2+
ErrorLike,
3+
NotFoundError,
4+
NotLoggedInError,
5+
NotMemberError,
6+
PageSnapshotList,
7+
PageSnapshotResult,
8+
} from "../deps/scrapbox-rest.ts";
9+
import { cookie } from "./auth.ts";
10+
import { BaseOptions, Result, setDefaults } from "./util.ts";
11+
import { makeError } from "./error.ts";
12+
13+
/** 不正な`timestampId`を渡されたときに発生するエラー */
14+
export interface InvalidPageSnapshotIdError extends ErrorLike {
15+
name: "InvalidPageSnapshotIdError";
16+
}
17+
18+
/** get a page snapshot
19+
*
20+
* @param options connect.sid etc.
21+
*/
22+
export const getSnapshot = async (
23+
project: string,
24+
pageId: string,
25+
timestampId: string,
26+
options?: BaseOptions,
27+
): Promise<
28+
Result<
29+
PageSnapshotResult,
30+
| NotFoundError
31+
| NotLoggedInError
32+
| NotMemberError
33+
| InvalidPageSnapshotIdError
34+
>
35+
> => {
36+
const { sid, hostName, fetch } = setDefaults(options ?? {});
37+
38+
const req = new Request(
39+
`https://${hostName}/api/page-snapshots/${project}/${pageId}/${timestampId}`,
40+
sid ? { headers: { Cookie: cookie(sid) } } : undefined,
41+
);
42+
43+
const res = await fetch(req);
44+
45+
if (!res.ok) {
46+
if (res.status === 422) {
47+
return {
48+
ok: false,
49+
value: {
50+
name: "InvalidPageSnapshotIdError",
51+
message: await res.text(),
52+
},
53+
};
54+
}
55+
return makeError<NotFoundError | NotLoggedInError | NotMemberError>(res);
56+
}
57+
58+
const value = (await res.json()) as PageSnapshotResult;
59+
return { ok: true, value };
60+
};
61+
62+
/**
63+
* Retrieves the timestamp IDs for a specific page in a project.
64+
*
65+
* @param project - The name of the project.
66+
* @param pageId - The ID of the page.
67+
* @param options - Optional configuration options.
68+
* @returns A promise that resolves to a {@link Result} object containing the page snapshot list if successful,
69+
* or an error if the request fails.
70+
*/
71+
export const getTimestampIds = async (
72+
project: string,
73+
pageId: string,
74+
options?: BaseOptions,
75+
): Promise<
76+
Result<PageSnapshotList, NotFoundError | NotLoggedInError | NotMemberError>
77+
> => {
78+
const { sid, hostName, fetch } = setDefaults(options ?? {});
79+
80+
const req = new Request(
81+
`https://${hostName}/api/page-snapshots/${project}/${pageId}`,
82+
sid ? { headers: { Cookie: cookie(sid) } } : undefined,
83+
);
84+
85+
const res = await fetch(req);
86+
87+
if (!res.ok) {
88+
return makeError<NotFoundError | NotLoggedInError | NotMemberError>(res);
89+
}
90+
91+
const value = (await res.json()) as PageSnapshotList;
92+
return { ok: true, value };
93+
};

0 commit comments

Comments
 (0)