Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@inpageedit/cli",
"version": "0.2.0",
"version": "0.2.1",
"description": "InPageEdit CLI for MediaWiki profiles and page editing",
"license": "MIT",
"homepage": "https://github.com/inpageedit/inpageedit-next/tree/master/packages/cli#readme",
Expand Down Expand Up @@ -38,7 +38,7 @@
"@napi-rs/keyring": "^2.1.2",
"diff": "^8.0.2",
"undici": "^7.30.2",
"wiki-saikou": "7.5.0"
"wiki-saikou": "7.8.0"
},
"devDependencies": {
"@types/node": "^22.18.12",
Expand Down
27 changes: 9 additions & 18 deletions packages/cli/src/wiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,33 +114,24 @@ async function cacheSession(
profile: Profile,
{ wiki, identity }: Session & { identity: Identity }
) {
const { hostname, pathname } = new URL(profile.api)
const jar = (wiki.request as any).cookieJar
const cookies = jar.getCookies(hostname, pathname).map((cookie: any) => {
const { maxAge, _createdAt, ...rest } = cookie
// CookieJar.setCookie resets Max-Age on insert. Persist its original absolute expiry.
const expires = maxAge === undefined ? rest.expires : new Date(+_createdAt + maxAge * 1000)
return { ...rest, expires }
})
await saveSession(profile, { username: identity.username, cookies })
await saveSession(profile, { username: identity.username, cookies: wiki.cookieJar.toJSON() })
}

async function restoreSession(profile: Profile): Promise<Session | undefined> {
const cached = (await savedSession(profile)) as
| { username?: unknown; cookies?: any[] }
| { username?: unknown; cookies?: unknown }
| undefined
if (typeof cached?.username !== 'string' || !Array.isArray(cached.cookies)) return
const wiki = client(profile.api)
const jar = (wiki.request as any).cookieJar
const now = Date.now()
for (const cookie of cached.cookies) {
if (typeof cookie?.name !== 'string' || typeof cookie.value !== 'string') return
const expires = cookie.expires === undefined ? undefined : new Date(cookie.expires)
if (expires && !(+expires > now)) continue
jar.setCookie({ ...cookie, expires })
try {
// No verification request: an expired session surfaces as assertuserfailed on the
// first operation, which withWikiSession answers by logging in with the password.
await wiki.login({ cookies: cached.cookies, assertuser: cached.username, verify: false })
} catch {
return // malformed cache: fall back to password login
}
const { hostname, pathname } = new URL(profile.api)
if (jar.getCookies(hostname, pathname).length) return session(wiki, cached.username)
if (wiki.cookieJar.getCookies(hostname, pathname).length) return session(wiki, cached.username)
}

function apiErrorCode(error: unknown): string | undefined {
Expand Down
17 changes: 15 additions & 2 deletions pnpm-lock.yaml

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

4 changes: 4 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ allowBuilds:
'@parcel/watcher': true
esbuild: true

minimumReleaseAgeExclude:
- fexios
- wiki-saikou

onlyBuiltDependencies:
- '@parcel/watcher'
- esbuild