Skip to content

Commit

Permalink
Updater
Browse files Browse the repository at this point in the history
  • Loading branch information
pyxfluff committed Jan 18, 2025
1 parent 4ef9cd9 commit d261c1d
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 69 deletions.
17 changes: 17 additions & 0 deletions src/Client/Client/Modules/Frontend.luau
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,21 @@ function Frontend.Close(Instant: boolean): ()
end)
end

function Frontend.CheckForUpdates(
Products: {}?
): ()
--// TODO: Full product checking, need to redo this regardless
local Label = Var.MainFrame.Configuration.InfoPage.VersionDetails.Update.Label
Label.Text = "CHECKING"

--// fake slowdown lol
task.wait(0.25)
Var.Remotes.CheckForUpdates:InvokeServer()
Label.Text = "COMPLETE"

task.delay(3, function()
Label.Text = "CHECK FOR UPDATES"
end)
end

return Frontend
2 changes: 2 additions & 0 deletions src/Server/Core/Locales/en-us.luau
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ return {

["update.Check"] = "Check for Updates",
["update.Done"] = "Complete",
["updater.Failed.Body"] = "This might be an issue with online services, please try again later; code %s",
["updater.Failed.Header"] = "Version check failed",

["donations.Done"] = "Thank you for your support, %s! Your donation helps ensure future Administer updates for years to come ^^",
["donations.DonationProcessed"] = "Your donation helps give back to the open-source community and will ensure: - lots of updates in the future - development funding for more apps - app server hosting Your donation means a lot to us! Make sure to show us this to claim your donor perks.",
Expand Down
2 changes: 2 additions & 0 deletions src/Server/Core/Locales/es-es.luau
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ return {

["update.Check"] = "Buscar Actualizaciones",
["update.Done"] = "Completo",
["updater.Failed.Body"] = "Esto podría ser un problema con los servicios en línea, inténtelo nuevamente más tarde; código %s",
["updater.Failed.Header"] = "Error en la comprobación de la versión",

["donations.Done"] = "¡Gracias por tu apoyo, %s! Tu donación ayuda a asegurar futuras actualizaciones de Administer en los años venideros ^^",
["donations.DonationProcessed"] = "Su donación ayuda a devolver a la comunidad de código abierto y asegurará: - muchas actualizaciones en el futuro - financiación para el desarrollo de más aplicaciones - alojamiento del servidor de aplicaciones ¡Su donación significa mucho para nosotros! Asegúrate de mostrarnos esto para reclamar tus ventajas de donante.",
Expand Down
60 changes: 60 additions & 0 deletions src/Server/Core/Types.luau
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,64 @@ export type ActionObject = {
OnClick: () -> (),
}

export type AdmBranch = {
ImageID: string,
Name: string,
IsActive: boolean
}

type Version = string
type Branch = "LIVE" | "BETA" | "CANARY" | "INTERNAL" | "GIT"
type AdministerDistributors = {"git" | "roblox" | "pesde" | "aos"}
type BranchList = {"LIVE" | "BETA" | "CANARY" | "INTERNAL" | "GIT"}

export type PythonVersionInfo = {
provided_information: {
branch: BranchList,
version: string,
outdated: boolean,

can_update_to: {
branch: Branch,
name: string
},

featureset: {
apps: {
can_download: boolean,
can_install_new: boolean,
can_access_marketplace: boolean
},

administer: {
can_auto_update: boolean,
can_report_version: boolean
},

misc: {
supports_ranks: {string}
}
}
},

versions: {
[Version] : {
latest: boolean,
available_to: BranchList,
distributed_via: AdministerDistributors,
released: number,
hash: string,

logs: {string}
},
}
}

export type HomeWidgetInfo = {
_version: string,
Widget1: string,
Widget2: string,
TextWidgets: {string}
}

return {}
21 changes: 11 additions & 10 deletions src/Server/Core/Variables.luau
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
--// Administer
--// (pyxfluff + FloofyPlasma) 2024 - 2025
-- stylua: ignore start

local Variables = {}

local Typing = require(script.Parent.Types)

--// The items below this until the warning may be edited if you wish and it will not compromise Administer's security or functionality.
--// If you change too many functionality-related variables and Administer does not boot you will NOT be elligible for support.
Variables.Config = require(script.Parent.Configuration)
Expand Down Expand Up @@ -53,6 +56,11 @@ Variables.DataStores = {
Settings = Variables.Services.DataStoreService:GetDataStore("Administer_Settings")
}

Variables.Notification = {
Ding = "",
Error = ""
}

--// WARNING: EVERYTHING BELOW THIS LINE IS AUTOMATED AND SHOULD NOT BE EDITED.
--// IF YOU WANT TO HARDCODE ADMINS, SEE Configuration.luau
-- stylua: ignore end
Expand All @@ -76,7 +84,7 @@ Variables.InitClock = {

Variables.DefaultRank = {
["RankID"] = 0,
["RankName"] = require(Variables.Locales[Variables.DefaultLocale])["admin.RankDefault"],
["RankName"] = (require(Variables.Locales[Variables.DefaultLocale]) :: any)["admin.RankDefault"],
["Protected"] = false,

["Members"] = {},
Expand All @@ -100,42 +108,35 @@ Variables.CurrentBranch = { Name = "" }
Variables.Branches = {
["Interal"] = {
["ImageID"] = "rbxassetid://18841275783",
["UpdateLog"] = 18336751142,
["Name"] = "Administer Internal",
["IsActive"] = false,
},

["QA"] = {
["ImageID"] = "rbxassetid://76508533583525",
["UpdateLog"] = 18336751142,
["Name"] = "Administer QA",
["IsActive"] = false,
},

["Canary"] = {
["ImageID"] = "rbxassetid://18841275783",
["UpdateLog"] = 18841988915,
["Name"] = "Administer Canary",
["IsActive"] = false,
},

["Beta"] = {
["ImageID"] = "rbxassetid://18770010888",
["UpdateLog"] = 18336751142,
["Name"] = "Administer Beta",
["IsActive"] = false,
},

["Live"] = {
["ImageID"] = "rbxassetid://18224047110",
["UpdateLog"] = 18336751142,
["Name"] = "Administer",
["IsActive"] = true,
},
}

Variables.CurrentBranch = nil

Variables.Panel = {
Path = script.Parent.Parent.Resources.AdministerMainPanel,
}
Expand All @@ -158,7 +159,7 @@ Variables.Panel.Spawn = function(Rank, Player)
)
NewPanel:SetAttribute(
"_InstalledApps",
Variables.Services.HttpService:JSONEncode(require(script.Parent.Parent.Modules.AppAPI).AllApps)
Variables.Services.HttpService:JSONEncode((require(script.Parent.Parent.Modules.AppAPI).AllApps) :: any)
)
NewPanel:SetAttribute("_CurrentBranch", Variables.Services.HttpService:JSONEncode(Variables.CurrentBranch))

Expand All @@ -170,7 +171,7 @@ Variables.Init = function()
RF.Name = "Administer"
Variables.RemotesPath = RF

for Branch, Object in Variables.Branches do
for Branch, Object: Typing.AdmBranch in Variables.Branches :: {Typing.AdmBranch} do
Object["BranchName"] = Branch

if Object["IsActive"] then Variables.CurrentBranch = Object end
Expand Down
93 changes: 45 additions & 48 deletions src/Server/Modules/Frontend.luau
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,64 @@
--// (pyxfluff + FloofyPlasma) 2024 - 2025

local FrontendAPI = {}

local Root = script:FindFirstAncestor("Loader")
local Utils = require(Root.Modules.Utilities)

local Var = require(Root.Core.Variables)
local HTTP = require(Root.Modules.HTTPRunner)
local Utils = require(Root.Modules.Utilities)

local Types = require(Root.Core.Types)

local Config = Var.Config

function FrontendAPI.NewUpdateLogText(ParentFrame, Text)
local Template = ParentFrame.ScrollingFrame.TextLabel:Clone()
function FrontendAPI.NewUpdateLogText(P: Player, Text)
local Template = P.ScrollingFrame.TextLabel:Clone()

Template.Visible = true
Template.Text = Text
Template.Name = Text
Template.Parent = ParentFrame.ScrollingFrame
Template.Parent = P.ScrollingFrame
end

function FrontendAPI.VersionCheck(Player: Player): ()
local VersModule, Frame =
require(Var.CurrentBranch["UpdateLog"]) :: any,
Player.PlayerGui.AdministerMainPanel.Main.Configuration.InfoPage.VersionDetails

for i, Label in Frame.ScrollingFrame:GetChildren() do
if Label:IsA("TextLabel") and Label.Name ~= "TextLabel" then Label:Destroy() end
end
function FrontendAPI.VersionCheck(Plr: Player): Types.Response
--// We need a better system for this
-- for i, Label in ScrollingFrame:GetChildren() do
-- if Label:IsA("TextLabel") and Label.Name ~= "TextLabel" then Label:Destroy() end
-- end
return HTTP.PostRoute(Var.DefaultAppServer, "/versions", {
current_version = Config.VersData.String
}, function(Data: Types.PythonVersionInfo, DebugInfo)
--// TODO
if Data.provided_information.outdated then
Utils.NewNotification(
Plr,
string.format(Utils.t(Plr, "updater.outofdate.Body")),
Utils.t(Plr, "updater.outofdate.Header"),
Utils.Icon("check"),
15,
Var.Notification.Ding,
{}
)

if
VersModule.Version.Major > Config.VersData.Major
or VersModule.Version.Minor > Config.VersData.Minor
or VersModule.Version.Tweak > Config.VersData.Tweak
then
Frame.Version.Text = `Version {Config.VersData.String}` --// don't include the date bc we don't store that here
Utils.NewNotification(
Player,
`{Config["Name"]} is out of date. Please update your module.`,
"Version check complete",
"rbxassetid://9894144899",
15,
nil,
{
{
["Text"] = "Visit the update center..",
["Icon"] = "",
["Callback"] = function()
--// TODO
return
end,
},
}
)
for _, Change in Data.versions[Data.provided_information.can_update_to.name].logs do
FrontendAPI.NewUpdateLogText(Plr, Change)
end
end

-- TODO
FrontendAPI.NewUpdateLogText(
nil :: any,
`A new version is available! {VersModule.Version.String} was released on {VersModule.ReleaseDate}. Showing the logs from that update.`
)
else
Frame.Version.Text = `Version {VersModule.Version.String} ({VersModule.ReleaseDate})`
end
return
end,

for i, Note in VersModule.ReleaseNotes do
FrontendAPI.NewUpdateLogText(Note)
end
function(StatusCode)
Utils.NewNotification(Plr,
string.format(Utils.t(Plr, "updater.Failed.Body"), tostring(StatusCode)),
Utils.t(Plr, "updater.Failed.Header"),
Utils.Icon("Plr-warning"),
99999,
Var.Notification.Ding,
{}
)
return
end, nil, nil)
end

return FrontendAPI
38 changes: 29 additions & 9 deletions src/Server/Modules/HTTPRunner.luau
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
local Root = script:FindFirstAncestor("Loader")
local Types = require(Root.Core.Types)
local Var = require(Root.Core.Variables)
local _Utils = require(Root.Modules.Utilities)
local Config = require(Root.Core.Configuration)

local Http = {}

Expand Down Expand Up @@ -36,27 +36,47 @@ function Http.GetRoute(AppServer, Route, OnOK, OnError): Types.Response
end
end

function Http.PostRoute(AppServer, Route, Body, OnOK, OnError): Types.Response
--<strong>WARNING: THIS DOES NOT ACTUALLY RETURN A { Response }, IT JUST SAYS THAT TO NOT HAVE THE TYPESOLVER COMPLAIN!</strong>
-- For more information on this API, please refer to the documentation: https://docs.administer.notpyx.me
function Http.PostRoute(
AppServer: string,
Route: string,
Body: {},
OnOK: (any, {ProcTime: number, RespMessage: string, Code: number}) -> (any),
OnError: (any) -> (any),
MiscConfig: nil | {Headers: {}},
DoAnyways: nil | (any) -> (any)
): Types.Response
local ST = tick()
local FinalHeaders = {}

if MiscConfig ~= nil then
for Key, Header in MiscConfig.Headers do
FinalHeaders[Key] = Header
end
else
FinalHeaders = {["X-Administer-Version"] = Config.VersData.String}
end

local Response = Var.Services.HttpService:RequestAsync({
Url = `{AppServer}{Route}`,
Method = "POST",
Headers = {
--// TODO
["X-Administer-Version"] = "0.0.0",
},
Headers = FinalHeaders,
Body = Var.Services.HttpService:JSONEncode(Body),
})

if Response.StatusCode == 200 then
if DoAnyways ~= nil then
DoAnyways(Response)
end

if string.sub(tostring(Response.StatusCode), 0, 1) == '2' then
return OnOK(Var.Services.HttpService:JSONDecode(Response.Body), {
ProcTime = tick() - ST,
RespMessage = Response.StatusMessage,
Code = 200,
Code = Response.StatusMessage,
})
else
return OnError(Response.StatusCode)
return OnError(Response.StatusCode :: number)
end
end

Expand Down
8 changes: 6 additions & 2 deletions src/Server/Modules/Utilities.luau
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ end

Utils.NewNotification = function(Admin: Player, Body, Title, Icon, Duration, NotificationSound, Options)
--// Spawns a new admin notification. Yields, use with task.spawn to avoid.
local Panel = Admin.PlayerGui.AdministerMainPanel
local Panel = (Admin.PlayerGui.AdministerMainPanel :: any) :: any
local OpenTime = 1.25

local Placeholder = Instance.new("Frame")
Expand Down Expand Up @@ -371,8 +371,12 @@ function Utils.t(Player: Player | nil, Key: string): string
Var.CachedLocales[Player.UserId] or Var.DataStores.Settings:GetAsync(Player.UserId .. "Locale")
)

return require(Locales:FindFirstChild(LocaleResult and LocaleResult or "en-us"))[Key] or Key
return (require(Locales:FindFirstChild(LocaleResult and LocaleResult or "en-us")) :: any)[Key] or Key
end
end

function Utils.Icon(IconID: string): string
return require(script.Parent.Parent.Core.Icons)[IconID]
end

return Utils

0 comments on commit d261c1d

Please sign in to comment.