home page for App
This commit is contained in:
@@ -1,19 +1,76 @@
|
||||
using SQLite;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SQLite;
|
||||
|
||||
namespace Blahblah.FlowerApp.Data;
|
||||
|
||||
public sealed class Constants
|
||||
internal sealed class Constants
|
||||
{
|
||||
public const string CategoryOther = "other";
|
||||
public const string EventUnknown = "unknown";
|
||||
|
||||
public const string BaseUrl = "https://flower.tsanie.org";
|
||||
public const string ApiVersionName = "api_version";
|
||||
public const string LastTokenName = "last_token";
|
||||
|
||||
public const string BaseUrl = "https://app.blahblaho.com";
|
||||
|
||||
public const SQLiteOpenFlags SQLiteFlags =
|
||||
SQLiteOpenFlags.ReadWrite |
|
||||
SQLiteOpenFlags.Create |
|
||||
SQLiteOpenFlags.SharedCache;
|
||||
|
||||
private const string dbFilename = "flowerstory.db3";
|
||||
const string dbFilename = "flowerstory.db3";
|
||||
public static string DatabasePath => Path.Combine(FileSystem.AppDataDirectory, dbFilename);
|
||||
|
||||
static string? apiVersion;
|
||||
public static string? ApiVersion => apiVersion;
|
||||
|
||||
static string? authorization;
|
||||
public static string? Authorization => authorization;
|
||||
|
||||
public static void SetAuthorization(string auth)
|
||||
{
|
||||
authorization = auth;
|
||||
}
|
||||
|
||||
public static async Task<Definitions?> Initialize(ILogger logger, string? version, CancellationToken cancellation = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
var v = await Extensions.FetchAsync<string>("api/version", cancellation);
|
||||
apiVersion = v;
|
||||
|
||||
if (v != version)
|
||||
{
|
||||
var definition = await Extensions.FetchAsync<Definitions>($"api/consts?{v}", cancellation);
|
||||
return definition;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError("error occurs on fetching version and definitions, {error}", ex);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
internal record Definitions
|
||||
{
|
||||
public required string ApiVersion { get; init; }
|
||||
|
||||
public required Dictionary<int, NamedItem> Categories { get; init; }
|
||||
|
||||
public required Dictionary<int, EventItem> Events { get; init; }
|
||||
}
|
||||
|
||||
internal record NamedItem(string Name, string? Description)
|
||||
{
|
||||
public string Name { get; init; } = Name;
|
||||
|
||||
public string? Description { get; init; } = Description;
|
||||
}
|
||||
|
||||
internal record EventItem(string Name, string? Description, bool Unique) : NamedItem(Name, Description)
|
||||
{
|
||||
public bool Unique { get; init; } = Unique;
|
||||
}
|
||||
Reference in New Issue
Block a user