Skip to content

Commit

Permalink
Make botAccount config property optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Mar 31, 2024
1 parent b40ff3b commit e09c8ee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
13 changes: 6 additions & 7 deletions lib/musicbrainz-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export type IFormData = {[key: string]: string | number};
const debug = Debug('musicbrainz-api');

export interface IMusicBrainzConfig {
botAccount: {
botAccount?: {
username?: string,
password?: string
},
Expand Down Expand Up @@ -167,8 +167,7 @@ export interface ISessionInformation {
export class MusicBrainzApi {

public readonly config: IMusicBrainzConfig = {
baseUrl: 'https://musicbrainz.org',
botAccount: {}
baseUrl: 'https://musicbrainz.org'
};

private rateLimiter: RateLimitThreshold;
Expand Down Expand Up @@ -358,8 +357,8 @@ export class MusicBrainzApi {

public async login(): Promise<boolean> {

assert.ok(this.config.botAccount.username, 'bot username should be set');
assert.ok(this.config.botAccount.password, 'bot password should be set');
assert.ok(this.config.botAccount?.username, 'bot username should be set');
assert.ok(this.config.botAccount?.password, 'bot password should be set');

if (this.session && this.session.loggedIn) {
for (const cookie of await this.getCookies(this.options.prefixUrl as string)) {
Expand Down Expand Up @@ -429,8 +428,8 @@ export class MusicBrainzApi {

formData.csrf_session_key = this.session.csrf.sessionKey;
formData.csrf_token = this.session.csrf.token;
formData.username = this.config.botAccount.username;
formData.password = this.config.botAccount.password;
formData.username = this.config.botAccount?.username;
formData.password = this.config.botAccount?.password;
formData.remember_me = 1;

const response = await got.post(`${entity}/${mbid}/edit`, {
Expand Down
1 change: 0 additions & 1 deletion test/test-musicbrainz-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ async function makeSearchApi(): Promise<MusicBrainzApi> {
return new MusicBrainzApi({

baseUrl: 'https://musicbrainz.org',
botAccount: {},

/**
* Enable proxy, like Fiddler
Expand Down

0 comments on commit e09c8ee

Please sign in to comment.