1 // ----------------------------------------------------------------------------------------------
3 // / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___
4 // / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \
5 // / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | |
6 // /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_|
7 // ----------------------------------------------------------------------------------------------
9 // Copyright 2015-2024 Ćukasz "JustArchi" Domeradzki
10 // Contact: JustArchi@JustArchi.net
12 // Licensed under the Apache License, Version 2.0 (the "License");
13 // you may not use this file except in compliance with the License.
14 // You may obtain a copy of the License at
16 // http://www.apache.org/licenses/LICENSE-2.0
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the License is distributed on an "AS IS" BASIS,
20 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 // See the License for the specific language governing permissions and
22 // limitations under the License.
26 using System
.Threading
;
27 using System
.Threading
.Tasks
;
28 using ArchiSteamFarm
.Core
;
29 using ArchiSteamFarm
.IPC
.Controllers
.Api
;
30 using ArchiSteamFarm
.IPC
.Responses
;
31 using Microsoft
.AspNetCore
.Mvc
;
33 namespace ArchiSteamFarm
.CustomPlugins
.ExamplePlugin
;
35 // This is an example class which shows you how you can extend ASF's API with your own custom API routes and controllers
36 // You're free to decide whether you want to integrate with existing ASF concepts (such as ArchiController/GenericResponse), or roll out your own
37 // All API controllers will be discovered during our Kestrel initialization using attributes mapping, you're also getting usual ASF goodies such as swagger documentation out of the box
39 public sealed class CatController
: ArchiController
{
41 /// Fetches URL of a random cat picture.
44 [ProducesResponseType
<GenericResponse
<Uri
>>((int) HttpStatusCode
.OK
)]
45 [ProducesResponseType
<GenericResponse
>((int) HttpStatusCode
.ServiceUnavailable
)]
46 public async Task
<ActionResult
<GenericResponse
>> CatGet() {
47 if (ASF
.WebBrowser
== null) {
48 throw new InvalidOperationException(nameof(ASF
.WebBrowser
));
51 CancellationToken cancellationToken
= HttpContext
.RequestAborted
;
53 Uri
? url
= await CatAPI
.GetRandomCatURL(ASF
.WebBrowser
, cancellationToken
).ConfigureAwait(false);
55 return url
!= null ? Ok(new GenericResponse
<Uri
>(url
)) : StatusCode((int) HttpStatusCode
.ServiceUnavailable
, new GenericResponse(false));