-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webui): claim server from login screen
closes #207
- Loading branch information
Showing
6 changed files
with
117 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import KomgaClaimService from '@/services/komga-claim.service' | ||
import { AxiosInstance } from 'axios' | ||
import _Vue from 'vue' | ||
|
||
export default { | ||
install ( | ||
Vue: typeof _Vue, | ||
{ http }: { http: AxiosInstance }) { | ||
Vue.prototype.$komgaClaim = new KomgaClaimService(http) | ||
}, | ||
} | ||
|
||
declare module 'vue/types/vue' { | ||
interface Vue { | ||
$komgaClaim: KomgaClaimService; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { AxiosInstance } from 'axios' | ||
|
||
const API_CLAIM = '/api/v1/claim' | ||
|
||
export default class KomgaClaimService { | ||
private http: AxiosInstance | ||
|
||
constructor (http: AxiosInstance) { | ||
this.http = http | ||
} | ||
|
||
async getClaimStatus (): Promise<ClaimStatus> { | ||
try { | ||
return (await this.http.get(API_CLAIM)).data | ||
} catch (e) { | ||
let msg = 'An error occurred while trying to retrieve claim status' | ||
if (e.response.data.message) { | ||
msg += `: ${e.response.data.message}` | ||
} | ||
throw new Error(msg) | ||
} | ||
} | ||
|
||
async claimServer (user: ClaimAdmin): Promise<UserDto> { | ||
try { | ||
return (await this.http.post(API_CLAIM, {}, { | ||
headers: { | ||
'X-Komga-Email': user.email, | ||
'X-Komga-Password': user.password, | ||
}, | ||
})).data | ||
} catch (e) { | ||
let msg = 'An error occurred while trying to claim server' | ||
if (e.response.data.message) { | ||
msg += `: ${e.response.data.message}` | ||
} | ||
throw new Error(msg) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
interface ClaimStatus { | ||
isClaimed: boolean | ||
} | ||
|
||
interface ClaimAdmin { | ||
email: string, | ||
password: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters