Add ability to disabled instances (#33)

This commit is contained in:
Daniel J. Summers 2022-07-08 14:46:29 -04:00
parent b591bf746c
commit bf5a3a95c4
8 changed files with 49 additions and 23 deletions

View File

@ -43,6 +43,10 @@ export interface Instance {
abbr : string abbr : string
/** The client ID (assigned by the Mastodon server) */ /** The client ID (assigned by the Mastodon server) */
clientId : string clientId : string
/** Whether this instance is enabled */
isEnabled : boolean
/** If disabled, the reason why it is disabled */
reason : string
} }
/** A job listing */ /** A job listing */

View File

@ -5,7 +5,10 @@ article
template(v-else) template(v-else)
p.text-center Please select your No Agenda-affiliated Mastodon instance p.text-center Please select your No Agenda-affiliated Mastodon instance
p.text-center(v-for="it in instances" :key="it.abbr") p.text-center(v-for="it in instances" :key="it.abbr")
button.btn.btn-primary(@click.prevent="select(it.abbr)") {{it.name}} template(v-if="it.isEnabled")
button.btn.btn-primary(@click.prevent="select(it.abbr)") {{it.name}}
template(v-else).
#[button.btn.btn-secondary(disabled="disabled") {{it.name}}]#[br]#[em {{it.reason}}]
</template> </template>
<script setup lang="ts"> <script setup lang="ts">

View File

@ -13,9 +13,10 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Markdig" Version="0.25.0" /> <PackageReference Include="Markdig" Version="0.30.2" />
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
<PackageReference Include="NodaTime" Version="3.0.5" /> <PackageReference Include="NodaTime" Version="3.1.0" />
<PackageReference Update="FSharp.Core" Version="6.0.5" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -79,15 +79,19 @@ type Count =
/// An instance of a Mastodon server which is configured to work with Jobs, Jobs, Jobs /// An instance of a Mastodon server which is configured to work with Jobs, Jobs, Jobs
type MastodonInstance () = type MastodonInstance () =
/// The name of the instance /// The name of the instance
member val Name = "" with get, set member val Name = "" with get, set
/// The URL for this instance /// The URL for this instance
member val Url = "" with get, set member val Url = "" with get, set
/// The abbreviation used in the URL to distinguish this instance's return codes /// The abbreviation used in the URL to distinguish this instance's return codes
member val Abbr = "" with get, set member val Abbr = "" with get, set
/// The client ID (assigned by the Mastodon server) /// The client ID (assigned by the Mastodon server)
member val ClientId = "" with get, set member val ClientId = "" with get, set
/// The cryptographic secret (provided by the Mastodon server) /// The cryptographic secret (provided by the Mastodon server)
member val Secret = "" with get, set member val Secret = "" with get, set
/// Whether the instance is currently enabled
member val IsEnabled = true with get, set
/// If an instance is disabled, the reason for it being disabled
member val Reason = "" with get, set
/// The authorization options for Jobs, Jobs, Jobs /// The authorization options for Jobs, Jobs, Jobs
@ -105,13 +109,17 @@ type AuthOptions () =
/// The Mastodon instance data provided via the Jobs, Jobs, Jobs API /// The Mastodon instance data provided via the Jobs, Jobs, Jobs API
type Instance = type Instance =
{ /// The name of the instance { /// The name of the instance
name : string name : string
/// The URL for this instance /// The URL for this instance
url : string url : string
/// The abbreviation used in the URL to distinguish this instance's return codes /// The abbreviation used in the URL to distinguish this instance's return codes
abbr : string abbr : string
/// The client ID (assigned by the Mastodon server) /// The client ID (assigned by the Mastodon server)
clientId : string clientId : string
/// Whether this instance is currently enabled
isEnabled : bool
/// If not enabled, the reason the instance is disabled
reason : string
} }

View File

@ -63,7 +63,7 @@ let configureServices (svc : IServiceCollection) =
svc.Configure<AuthOptions> (cfg.GetSection "Auth") |> ignore svc.Configure<AuthOptions> (cfg.GetSection "Auth") |> ignore
let dbCfg = cfg.GetSection "Rethink" let dbCfg = cfg.GetSection "Rethink"
let log = svcs.GetRequiredService<ILoggerFactory>().CreateLogger (nameof Data.Startup) let log = svcs.GetRequiredService<ILoggerFactory>().CreateLogger "JobsJobsJobs.Api.Data.Startup"
let conn = Data.Startup.createConnection dbCfg log let conn = Data.Startup.createConnection dbCfg log
svc.AddSingleton conn |> ignore svc.AddSingleton conn |> ignore
Data.Startup.establishEnvironment dbCfg log conn |> Data.awaitIgnore Data.Startup.establishEnvironment dbCfg log conn |> Data.awaitIgnore

View File

@ -182,11 +182,13 @@ module Instances =
/// Convert a Mastodon instance to the one we use in the API /// Convert a Mastodon instance to the one we use in the API
let private toInstance (inst : MastodonInstance) = let private toInstance (inst : MastodonInstance) =
{ name = inst.Name { name = inst.Name
url = inst.Url url = inst.Url
abbr = inst.Abbr abbr = inst.Abbr
clientId = inst.ClientId clientId = inst.ClientId
} isEnabled = inst.IsEnabled
reason = inst.Reason
}
// GET: /api/instances // GET: /api/instances
let all : HttpHandler = fun next ctx -> task { let all : HttpHandler = fun next ctx -> task {

View File

@ -28,7 +28,9 @@
<PackageReference Include="NodaTime.Serialization.JsonNet" Version="3.0.0" /> <PackageReference Include="NodaTime.Serialization.JsonNet" Version="3.0.0" />
<PackageReference Include="Polly" Version="7.2.2" /> <PackageReference Include="Polly" Version="7.2.2" />
<PackageReference Include="RethinkDb.Driver" Version="2.3.150" /> <PackageReference Include="RethinkDb.Driver" Version="2.3.150" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.11.1" /> <PackageReference Include="RethinkDb.Driver.FSharp" Version="0.9.0-beta-05" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.21.0" />
<PackageReference Update="FSharp.Core" Version="6.0.5" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -5,17 +5,23 @@
"0": { "0": {
"Name": "No Agenda Social", "Name": "No Agenda Social",
"Url": "https://noagendasocial.com", "Url": "https://noagendasocial.com",
"Abbr": "nas" "Abbr": "nas",
"IsEnabled": true,
"Reason": ""
}, },
"1": { "1": {
"Name": "ITM Slaves!", "Name": "ITM Slaves!",
"Url": "https://itmslaves.com", "Url": "https://itmslaves.com",
"Abbr": "itm" "Abbr": "itm",
"IsEnabled": false,
"Reason": "This site has changed platforms, and its integration is not yet restored"
}, },
"2": { "2": {
"Name": "Liberty Woof", "Name": "Liberty Woof",
"Url": "https://libertywoof.com", "Url": "https://libertywoof.com",
"Abbr": "lw" "Abbr": "lw",
"IsEnabled": false,
"Reason": "This site may have gone away; it is currently inaccessible"
} }
} }
} }