Skip to content

Commit 335caf0

Browse files
committed
fix(atcoder): compat with new memory limit format
1 parent 2bd4bd5 commit 335caf0

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

src/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
/**
2-
* Some general utilities.
3-
*
2+
* This entry point exports some utilities.
43
* Most of the time, you will want to do like this:
54
*
65
* ```ts
76
* import Codeforces from '@un-oj/core/platforms/codeforces';
7+
* const cf = new Codeforces();
88
* ```
9+
*
10+
* See {@link Platform} for the common behavior and conventions of all platforms,
11+
* such as method names, error handling, etc.
12+
*
13+
* @module
914
*/
1015

16+
// eslint-disable-next-line unused-imports/no-unused-imports
17+
import type { Platform } from './platform';
18+
1119
export * from './contest';
1220
export * from './platform';
1321
export * from './problem';

src/platform.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,16 @@ export interface PlatformOptions<Locale extends string | never = never> {
1919
locale?: Locale
2020
}
2121

22-
/** An Online Judge platform. */
22+
/**
23+
* The base class for all platforms.
24+
* Checkout the properties and methods to see what's available.
25+
*
26+
* ## Conventions
27+
*
28+
* - When a method is not implemented, it should throw an {@link UnsupportedError}.
29+
* - When a resource is not found, it should throw a {@link NotFoundError}.
30+
* - When the response is unexpected, it should throw an {@link UnexpectedResponseError}.
31+
*/
2332
export abstract class Platform<Locale extends string | never = never> {
2433
readonly ofetch: $Fetch;
2534
readonly baseURL: string;

src/platforms/hydro.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { PlatformOptions } from '../platform';
77
import type { Problem as BaseProblem, ProblemIOSample } from '../problem';
88
import { FetchError } from 'ofetch';
99
import { NotFoundError, Platform, UnexpectedResponseError } from '../platform';
10-
import { addHeaders, getFirstKey, UnOJError } from '../utils';
10+
import { getFirstKey, UnOJError } from '../utils';
1111

1212
export type ProblemType = 'traditional' | 'interactive' | 'submission' | 'objective';
1313

@@ -70,16 +70,7 @@ export const DEFAULT_BASE_URL = 'https://hydro.ac';
7070
/** HydroOJ platform. */
7171
export default class Hydro extends Platform<string> {
7272
constructor(options?: PlatformOptions<string>) {
73-
super({
74-
...options,
75-
ofetchDefaults: {
76-
...options?.ofetchDefaults,
77-
headers: addHeaders(
78-
options?.ofetchDefaults?.headers,
79-
[['accept', 'application/json']],
80-
),
81-
},
82-
}, DEFAULT_BASE_URL);
73+
super(options, DEFAULT_BASE_URL);
8374
}
8475

8576
/**
@@ -92,7 +83,10 @@ export default class Hydro extends Platform<string> {
9283

9384
try {
9485
data = await this.ofetch(path, {
95-
params: { pjax: 1 },
86+
query: { pjax: 1 },
87+
headers: {
88+
accept: 'application/json',
89+
},
9690
responseType: 'json',
9791
});
9892
} catch (e) {

src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const MEMORY_UNITS: Record<string, number> = {
2727
megabyte: 1024 * 1024,
2828
megabytes: 1024 * 1024,
2929
MB: 1024 * 1024,
30+
MiB: 1024 * 1024,
3031
};
3132

3233
/**

0 commit comments

Comments
 (0)