Skip to content

Commit

Permalink
Changed oauth params and Fixed ts build problems
Browse files Browse the repository at this point in the history
New OAuth param needed, cafter multiple client ids are accepted from server.
TS build failed on GitHub, added a tsconfig and fixed some ts errors/warnings.
  • Loading branch information
genius257 committed Aug 9, 2021
1 parent 095c0e8 commit 072f25e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
19 changes: 12 additions & 7 deletions src/api/PackageRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export default class PackageRepo {
"https://raw.githubusercontent.com/au3pm/action-test/master/";
static readonly repoBaseUrl = "https://raw.githubusercontent.com/";

private static _index?: Index = null;
private static _index: Index | null = null;

private static _packages: { [id: string]: Package } = {
au3pm: {
repo: "genius257/au3pm",
versions: <RepositoryRef[]>[] //WARNING: missing versions could be problematic later in development.
versions: <any>[] //WARNING: missing versions could be problematic later in development.
}
};

Expand Down Expand Up @@ -77,9 +77,12 @@ export default class PackageRepo {
);
}

static async getPackage(packageId: PackageName, version: string = null) {
static async getPackage(
packageId: PackageName,
version: string | null = null
) {
return this.getIndex()
.then((index?: Index) => index[packageId])
.then((index?: Index) => index?.[packageId])
.then((packageRef: PackagePathName) => {
return this.getPackageVersions(packageRef).then(
(packageVersions: Package) => {
Expand All @@ -88,9 +91,11 @@ export default class PackageRepo {
version ?? "*"
);
return (
this._cache?.[packageRef]?.[version] ??
this._cache?.[packageRef]?.[<string>version] ??
fetch(
`${this.repoBaseUrl}${packageVersions.repo}/${packageVersions.versions[version]}/au3pm.json`
`${this.repoBaseUrl}${packageVersions.repo}/${
packageVersions.versions[<string>version]
}/au3pm.json`
)
.then((response) =>
response.status === 404 ? {} : response.json()
Expand All @@ -115,7 +120,7 @@ export default class PackageRepo {
//FIXME: if cannot resolve, throw new Exception.
return Object.keys(packageVersions).reduce(
(previousValue, currentValue) =>
previousValue > currentValue ? previousValue : currentValue,
<any>previousValue > currentValue ? previousValue : currentValue,
null
);
}
Expand Down
6 changes: 5 additions & 1 deletion src/components/OAuth.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from "../app.json";
import React from "react";
import QueryString from "query-string";
import localStorage from "local-storage";
Expand All @@ -6,12 +7,15 @@ import "./OAuth.css";
export default class OAuth extends React.Component {
componentDidMount() {
const query = QueryString.parse(window.location.search);
fetch(`https://au3pm.green-tag.dk/?code=${query.code}`)
fetch(
`https://au3pm.green-tag.dk/?client_id=${config.github.client_id}&code=${query.code}`
)
.then((response) => response.json())
.then((json) => {
localStorage.set("ghtoken", json.access_token);
window.close();
});
//FIXME: add promise catch
}

render() {
Expand Down
23 changes: 23 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"outDir": "build/dist",
"module": "esnext",
"target": "es5",
"lib": [
"es6",
"dom"
],
"sourceMap": true,
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"rootDir": "src",
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true
}
}

0 comments on commit 072f25e

Please sign in to comment.