mirror of
https://github.com/sct/overseerr.git
synced 2025-09-17 17:24:35 +02:00
feat: generate real api key
This also hides the api key from users without the ADMIN permission. It will not be returned from the api for them. Regenerate functionality is not in the commit.
This commit is contained in:
@@ -102,7 +102,7 @@ class Settings {
|
||||
this.data = {
|
||||
clientId: '',
|
||||
main: {
|
||||
apiKey: 'temp',
|
||||
apiKey: '',
|
||||
applicationUrl: '',
|
||||
},
|
||||
plex: {
|
||||
@@ -144,6 +144,10 @@ class Settings {
|
||||
}
|
||||
|
||||
get main(): MainSettings {
|
||||
if (!this.data.main.apiKey) {
|
||||
this.data.main.apiKey = this.generateApiKey();
|
||||
this.save();
|
||||
}
|
||||
return this.data.main;
|
||||
}
|
||||
|
||||
@@ -200,6 +204,16 @@ class Settings {
|
||||
return this.data.clientId;
|
||||
}
|
||||
|
||||
public regenerateApiKey(): MainSettings {
|
||||
this.main.apiKey = this.generateApiKey();
|
||||
this.save();
|
||||
return this.main;
|
||||
}
|
||||
|
||||
private generateApiKey(): string {
|
||||
return Buffer.from(`${Date.now()}${this.clientId}`).toString('base64');
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings Load
|
||||
*
|
||||
|
Reference in New Issue
Block a user