Specify if we want to fallback to the server token

pull/4271/head
Chocobozzz 2021-07-08 10:55:16 +02:00
parent 04aed76711
commit a1637fa1e2
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
21 changed files with 122 additions and 35 deletions

View File

@ -12,8 +12,10 @@ export class BulkCommand extends AbstractCommand {
return this.postBodyRequest({
...options,
path: '/api/v1/bulk/remove-comments-of',
fields: attributes,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}

View File

@ -9,7 +9,9 @@ export class CustomPagesCommand extends AbstractCommand {
return this.getRequestBody<CustomPage>({
...options,
path,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -22,8 +24,10 @@ export class CustomPagesCommand extends AbstractCommand {
return this.putBodyRequest({
...options,
path,
fields: { content },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}

View File

@ -19,6 +19,7 @@ export class FeedCommand extends AbstractCommand {
path,
query: format ? { format } : undefined,
accept: 'application/xml',
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -36,6 +37,7 @@ export class FeedCommand extends AbstractCommand {
path,
query,
accept: 'application/json',
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}

View File

@ -17,6 +17,7 @@ export class LogsCommand extends AbstractCommand {
path,
query: { startDate, endDate, level },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -34,6 +35,7 @@ export class LogsCommand extends AbstractCommand {
path,
query: { startDate, endDate },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}

View File

@ -60,6 +60,7 @@ export class AbusesCommand extends AbstractCommand {
path,
fields: body,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
}))
}
@ -106,6 +107,7 @@ export class AbusesCommand extends AbstractCommand {
path,
query,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -138,6 +140,7 @@ export class AbusesCommand extends AbstractCommand {
path,
query,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -154,6 +157,7 @@ export class AbusesCommand extends AbstractCommand {
path,
fields: body,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
@ -164,7 +168,13 @@ export class AbusesCommand extends AbstractCommand {
const { abuseId } = options
const path = '/api/v1/abuses/' + abuseId
return this.deleteRequest({ ...options, path, defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 })
return this.deleteRequest({
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
listMessages (options: OverrideCommandOptions & {
@ -173,7 +183,13 @@ export class AbusesCommand extends AbstractCommand {
const { abuseId } = options
const path = '/api/v1/abuses/' + abuseId + '/messages'
return this.getRequestBody<ResultList<AbuseMessage>>({ ...options, path, defaultExpectedStatus: HttpStatusCode.OK_200 })
return this.getRequestBody<ResultList<AbuseMessage>>({
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
deleteMessage (options: OverrideCommandOptions & {
@ -183,7 +199,13 @@ export class AbusesCommand extends AbstractCommand {
const { abuseId, messageId } = options
const path = '/api/v1/abuses/' + abuseId + '/messages/' + messageId
return this.deleteRequest({ ...options, path, defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 })
return this.deleteRequest({
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
addMessage (options: OverrideCommandOptions & {
@ -198,6 +220,7 @@ export class AbusesCommand extends AbstractCommand {
path,
fields: { message },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}

View File

@ -7,7 +7,7 @@ export class OverviewsCommand extends AbstractCommand {
getVideos (options: OverrideCommandOptions & {
page: number
}) {
const { token, page } = options
const { page } = options
const path = '/api/v1/overviews/videos'
const query = { page }
@ -15,9 +15,9 @@ export class OverviewsCommand extends AbstractCommand {
return this.getRequestBody<VideosOverview>({
...options,
token: token || null,
path,
query,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}

View File

@ -25,16 +25,15 @@ export class SearchCommand extends AbstractCommand {
advancedChannelSearch (options: OverrideCommandOptions & {
search: VideoChannelsSearchQuery
}) {
const { search, token } = options
const { search } = options
const path = '/api/v1/search/video-channels'
return this.getRequestBody<ResultList<VideoChannel>>({
...options,
token: token || null,
path,
query: search,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -52,16 +51,15 @@ export class SearchCommand extends AbstractCommand {
advancedPlaylistSearch (options: OverrideCommandOptions & {
search: VideoPlaylistsSearchQuery
}) {
const { search, token } = options
const { search } = options
const path = '/api/v1/search/video-playlists'
return this.getRequestBody<ResultList<VideoPlaylist>>({
...options,
token: token || null,
path,
query: search,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -85,16 +83,15 @@ export class SearchCommand extends AbstractCommand {
advancedVideoSearch (options: OverrideCommandOptions & {
search: VideosSearchQuery
}) {
const { search, token } = options
const { search } = options
const path = '/api/v1/search/videos'
return this.getRequestBody<ResultList<Video>>({
...options,
token: token || null,
path,
query: search,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}

View File

@ -24,8 +24,8 @@ export class ConfigCommand extends AbstractCommand {
return this.getRequestBody<ServerConfig>({
...options,
token: null,
path,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -36,8 +36,8 @@ export class ConfigCommand extends AbstractCommand {
return this.getRequestBody<About>({
...options,
token: null,
path,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -49,6 +49,7 @@ export class ConfigCommand extends AbstractCommand {
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -63,6 +64,7 @@ export class ConfigCommand extends AbstractCommand {
path,
fields: options.newCustomConfig,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -74,6 +76,7 @@ export class ConfigCommand extends AbstractCommand {
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}

View File

@ -23,8 +23,8 @@ export class ContactFormCommand extends AbstractCommand {
...options,
path,
token: null,
fields: body,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}

View File

@ -11,6 +11,7 @@ export class DebugCommand extends AbstractCommand {
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -26,6 +27,7 @@ export class DebugCommand extends AbstractCommand {
path,
fields: body,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}

View File

@ -22,10 +22,9 @@ export class FollowsCommand extends AbstractCommand {
return this.getRequestBody<ResultList<ActorFollow>>({
...options,
token: null,
path,
query,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -46,10 +45,9 @@ export class FollowsCommand extends AbstractCommand {
return this.getRequestBody<ResultList<ActorFollow>>({
...options,
token: null,
path,
query,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -66,6 +64,7 @@ export class FollowsCommand extends AbstractCommand {
path,
fields: { hosts },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
@ -79,6 +78,7 @@ export class FollowsCommand extends AbstractCommand {
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
@ -92,6 +92,7 @@ export class FollowsCommand extends AbstractCommand {
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
@ -105,6 +106,7 @@ export class FollowsCommand extends AbstractCommand {
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
@ -118,6 +120,7 @@ export class FollowsCommand extends AbstractCommand {
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}

View File

@ -21,6 +21,7 @@ export class JobsCommand extends AbstractCommand {
path,
query,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}

View File

@ -45,6 +45,7 @@ export class PluginsCommand extends AbstractCommand {
pluginType,
uninstalled
},
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -75,6 +76,7 @@ export class PluginsCommand extends AbstractCommand {
path,
query,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -88,6 +90,7 @@ export class PluginsCommand extends AbstractCommand {
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -104,6 +107,7 @@ export class PluginsCommand extends AbstractCommand {
path,
fields: { settings },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
@ -117,6 +121,7 @@ export class PluginsCommand extends AbstractCommand {
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -131,6 +136,7 @@ export class PluginsCommand extends AbstractCommand {
...options,
path,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -145,6 +151,7 @@ export class PluginsCommand extends AbstractCommand {
...options,
path,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -161,6 +168,7 @@ export class PluginsCommand extends AbstractCommand {
path: apiPath,
fields: { npmName, path },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -177,6 +185,7 @@ export class PluginsCommand extends AbstractCommand {
path: apiPath,
fields: { npmName, path },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -192,6 +201,7 @@ export class PluginsCommand extends AbstractCommand {
path: apiPath,
fields: { npmName },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
@ -203,6 +213,7 @@ export class PluginsCommand extends AbstractCommand {
...options,
path,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -222,6 +233,7 @@ export class PluginsCommand extends AbstractCommand {
path,
query,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200,
redirects: 0
})

View File

@ -16,6 +16,7 @@ export class RedundancyCommand extends AbstractCommand {
path,
fields: { redundancyAllowed },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
@ -42,6 +43,7 @@ export class RedundancyCommand extends AbstractCommand {
target
},
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -57,6 +59,7 @@ export class RedundancyCommand extends AbstractCommand {
path,
fields: { videoId },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
@ -71,6 +74,7 @@ export class RedundancyCommand extends AbstractCommand {
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}

View File

@ -19,6 +19,7 @@ export class StatsCommand extends AbstractCommand {
path,
query,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}

View File

@ -1,5 +1,13 @@
import { HttpStatusCode } from '@shared/core-utils'
import { makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest, makeUploadRequest, unwrapBody, unwrapText } from '../requests/requests'
import {
makeDeleteRequest,
makeGetRequest,
makePostBodyRequest,
makePutBodyRequest,
makeUploadRequest,
unwrapBody,
unwrapText
} from '../requests/requests'
import { ServerInfo } from '../server/servers'
export interface OverrideCommandOptions {
@ -7,12 +15,14 @@ export interface OverrideCommandOptions {
expectedStatus?: number
}
interface CommonCommandOptions extends OverrideCommandOptions {
interface InternalCommonCommandOptions extends OverrideCommandOptions {
path: string
// If we automatically send the server token if the token is not provided
implicitToken: boolean
defaultExpectedStatus: number
}
interface GetCommandOptions extends CommonCommandOptions {
interface InternalGetCommandOptions extends InternalCommonCommandOptions {
query?: { [ id: string ]: any }
contentType?: string
accept?: string
@ -37,15 +47,15 @@ abstract class AbstractCommand {
this.expectedStatus = status
}
protected getRequestBody <T> (options: GetCommandOptions) {
protected getRequestBody <T> (options: InternalGetCommandOptions) {
return unwrapBody<T>(this.getRequest(options))
}
protected getRequestText (options: GetCommandOptions) {
protected getRequestText (options: InternalGetCommandOptions) {
return unwrapText(this.getRequest(options))
}
protected getRequest (options: GetCommandOptions) {
protected getRequest (options: InternalGetCommandOptions) {
const { redirects, query, contentType, accept } = options
return makeGetRequest({
@ -58,11 +68,11 @@ abstract class AbstractCommand {
})
}
protected deleteRequest (options: CommonCommandOptions) {
protected deleteRequest (options: InternalCommonCommandOptions) {
return makeDeleteRequest(this.buildCommonRequestOptions(options))
}
protected putBodyRequest (options: CommonCommandOptions & {
protected putBodyRequest (options: InternalCommonCommandOptions & {
fields?: { [ fieldName: string ]: any }
}) {
const { fields } = options
@ -74,7 +84,7 @@ abstract class AbstractCommand {
})
}
protected postBodyRequest (options: CommonCommandOptions & {
protected postBodyRequest (options: InternalCommonCommandOptions & {
fields?: { [ fieldName: string ]: any }
}) {
const { fields } = options
@ -86,7 +96,7 @@ abstract class AbstractCommand {
})
}
protected postUploadRequest (options: CommonCommandOptions & {
protected postUploadRequest (options: InternalCommonCommandOptions & {
fields?: { [ fieldName: string ]: any }
attaches?: any
}) {
@ -101,7 +111,7 @@ abstract class AbstractCommand {
})
}
protected putUploadRequest (options: CommonCommandOptions & {
protected putUploadRequest (options: InternalCommonCommandOptions & {
fields?: { [ fieldName: string ]: any }
attaches?: any
}) {
@ -116,15 +126,18 @@ abstract class AbstractCommand {
})
}
private buildCommonRequestOptions (options: CommonCommandOptions) {
private buildCommonRequestOptions (options: InternalCommonCommandOptions) {
const { token, expectedStatus, defaultExpectedStatus, path } = options
const fallbackToken = options.implicitToken
? this.server.accessToken
: undefined
return {
url: this.server.url,
path,
// Token can be null if we don't want to add it
token: token !== undefined ? token : this.server.accessToken,
token: token !== undefined ? token : fallbackToken,
statusCodeExpected: expectedStatus ?? this.expectedStatus ?? defaultExpectedStatus
}

View File

@ -17,6 +17,7 @@ export class AccountsCommand extends AbstractCommand {
path,
query: { sort },
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -30,6 +31,7 @@ export class AccountsCommand extends AbstractCommand {
...options,
path,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -48,6 +50,7 @@ export class AccountsCommand extends AbstractCommand {
path,
query,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}

View File

@ -56,6 +56,7 @@ export class BlocklistCommand extends AbstractCommand {
accountName: account,
host: server
},
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
@ -78,6 +79,7 @@ export class BlocklistCommand extends AbstractCommand {
accountName: account,
host: server
},
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
@ -98,6 +100,7 @@ export class BlocklistCommand extends AbstractCommand {
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
@ -116,6 +119,7 @@ export class BlocklistCommand extends AbstractCommand {
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
@ -128,6 +132,7 @@ export class BlocklistCommand extends AbstractCommand {
path,
query: { start, count, sort },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}

View File

@ -14,6 +14,7 @@ export class SubscriptionsCommand extends AbstractCommand {
path,
fields: { uri: options.targetUri },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
@ -33,6 +34,7 @@ export class SubscriptionsCommand extends AbstractCommand {
sort,
search
},
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -48,6 +50,7 @@ export class SubscriptionsCommand extends AbstractCommand {
path,
query: { sort },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -61,6 +64,7 @@ export class SubscriptionsCommand extends AbstractCommand {
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -74,6 +78,7 @@ export class SubscriptionsCommand extends AbstractCommand {
...options,
path,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
@ -88,6 +93,7 @@ export class SubscriptionsCommand extends AbstractCommand {
path,
query: { 'uris[]': options.uris },
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}

View File

@ -23,6 +23,7 @@ export class LiveCommand extends AbstractCommand {
...options,
path: path + '/' + options.videoId,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}
@ -39,6 +40,7 @@ export class LiveCommand extends AbstractCommand {
path: path + '/' + videoId,
fields,
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
})
}
@ -59,6 +61,7 @@ export class LiveCommand extends AbstractCommand {
path,
attaches,
fields: omit(fields, 'thumbnailfile', 'previewfile'),
implicitToken: true,
defaultExpectedStatus: HttpStatusCode.OK_200
}))

View File

@ -22,6 +22,7 @@ export class ServicesCommand extends AbstractCommand {
path,
query,
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.OK_200
})
}