Skip to content

Commit

Permalink
[optimize] upgrade to KoAJAX 3.0 & MobX-RESTful 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TechQuery committed Sep 3, 2024
1 parent ba2a2d9 commit 2df1dff
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 88 deletions.
11 changes: 5 additions & 6 deletions models/Base/File.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ export class AzureFileModel extends FileModel {

const { status, title, detail } = data as unknown as ErrorBaseData;

throw new HTTPError(detail || title, {
status,
statusText: title,
headers: header,
body: data,
});
throw new HTTPError(
detail || title,
{ method, path: fullPath, headers, body },
{ status, statusText: title, headers: header, body: data },
);
}

@toggle('uploading')
Expand Down
3 changes: 2 additions & 1 deletion models/Git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import sessionStore from './User/Session';
type Repository = components['schemas']['repository'];

githubClient.use(({ request }, next) => {
const { accessToken } = sessionStore.metaOAuth.github || {};
const { accessToken = process.env.GITHUB_PAT } =
sessionStore.metaOAuth.github || {};

if (accessToken)
request.headers = {
Expand Down
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
"echarts-jsx": "^0.5.4",
"idea-react": "^2.0.0-rc.2",
"jsonwebtoken": "^9.0.2",
"koajax": "^1.1.2",
"koajax": "^3.0.0",
"leaflet": "^1.9.4",
"leaflet.chinatmsproviders": "^3.0.6",
"mobx": "^6.13.1",
"mobx-github": "^0.3.2",
"mobx-i18n": "^0.5.0",
"mobx-react": "^9.1.1",
"mobx-react-helper": "^0.3.1",
"mobx-restful": "^0.7.0-rc.0",
"mobx-restful": "^1.0.0",
"mobx-restful-table": "^2.0.0-rc.1",
"next": "^14.2.7",
"next-ssr-middleware": "^0.8.7",
Expand All @@ -48,7 +48,7 @@
"@octokit/openapi-types": "^22.2.0",
"@types/jsonwebtoken": "^9.0.6",
"@types/leaflet": "^1.9.12",
"@types/node": "^20.16.2",
"@types/node": "^20.16.3",
"@types/react": "^18.3.5",
"eslint": "^8.57.0",
"eslint-config-next": "^14.2.7",
Expand All @@ -57,13 +57,18 @@
"husky": "^9.1.5",
"less": "^4.2.0",
"less-loader": "^12.2.0",
"lint-staged": "^15.2.9",
"lint-staged": "^15.2.10",
"next-pwa": "^5.6.0",
"next-with-less": "^3.0.1",
"prettier": "^3.3.3",
"typescript": "~5.5.4",
"webpack": "^5.94.0"
},
"resolutions": {
"native-file-system-adapter": "npm:@tech_query/[email protected]",
"koajax": "$koajax",
"mobx-restful": "$mobx-restful"
},
"prettier": {
"singleQuote": true,
"trailingComma": "all",
Expand Down
4 changes: 2 additions & 2 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ enableStaticRendering(isServer());
const { t } = i18n;

globalThis.addEventListener?.('unhandledrejection', ({ reason }) => {
const { message, body } = (reason || {}) as HTTPError<ErrorBaseData>;
const { message, response } = (reason || {}) as HTTPError<ErrorBaseData>;

const tips = body?.detail || message;
const tips = response.body?.detail || message;

if (tips) alert(tips);
});
Expand Down
3 changes: 2 additions & 1 deletion pages/api/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export function safeAPI(handler: NextAPI): NextAPI {
console.error(error);
return res.end(error);
}
let { message, status, body } = error;
const { message, response } = error;
let { status, body } = response;

res.status(status);
res.statusMessage = message;
Expand Down
2 changes: 1 addition & 1 deletion pages/open-source.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const getServerSideProps = compose<{}, OpenSourcePageProps>(
const repositoryStore = new SourceRepositoryModel();

const contributors = await repositoryStore.getAllContributors(),
repositories = repositoryStore.allItems;
repositories = JSON.parse(JSON.stringify(repositoryStore.allItems));

return { props: { repositories, contributors } };
},
Expand Down
Loading

1 comment on commit 2df1dff

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for open-hackathon ready!

✅ Preview
https://open-hackathon-b7ofqeie4-techquerys-projects.vercel.app

Built with commit 2df1dff.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.