Skip to content

Commit

Permalink
feat: update convars, readme and logs logic
Browse files Browse the repository at this point in the history
  • Loading branch information
itschip committed Jan 26, 2024
1 parent efb5e34 commit cfc35e0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Download the latest release from the
Add the following to your `server.cfg`:

```
set FIVEMANAGE_API_KEY your_api_key
set FIVEMANAGE_MEDIA_API_KEY your_api_key
set FIVEMANAGE_LOGS_API_KEY your_api_key
```

This is the key for authenticating with our backend.
Expand Down Expand Up @@ -63,10 +64,6 @@ print(imageData.url)

#### Levels

## Note

Only users with beta access can use logs right now. We'll update our discord and this readme when it is available for everyone! Hang in there!

- info
- warn
- error
Expand All @@ -81,8 +78,10 @@ Coming soon
exports.fivemanage_lib:LogMessage("error", "Failed to roleplay")

-- With metadata
exports.fivemanage_lib:LogMessage("error", "Failed to roleplay", {
playerName = "Dude",
playerIdentifier = someFunctionThatReturnsTheID(someArg)
exports.fivemanage_lib:LogMessage('info', "Someone did a bad thing", {
playerSource = 1, -- All identifiers will be automatically added
playerName = "John Doe",
coords = {x = 1, y = 2, z = 3},
-- or any other field you want
})
```
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ server_scripts {
"server/main.lua",

"server/dist/index.js",
}
}
4 changes: 2 additions & 2 deletions server/image/sv_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ onNet("fivemanage:takeImage", (metadata, requestId) => {
});

function uploadImage(data, metadata) {
const apiKey = GetConvar("FIVEMANAGE_API_KEY", "");
const apiKey = GetConvar("FIVEMANAGE_MEDIA_API_KEY", "");

if (!apiKey) {
console.error("FIVEMANAGE_API_KEY is not set");
console.error("FIVEMANAGE_MEDIA_API_KEY is not set");
return;
}

Expand Down
7 changes: 4 additions & 3 deletions server/logs/lib.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Logger = {}

local api_url = "https://api.fivemanage.com/api/logs"
local api_url = "https://cat-polished-marlin.ngrok-free.app/api/logs" --"https://api.fivemanage.com/api/logs"

local function print_to_console(message, log_level, metadata, resource)
local _log_level_color = log_level == "info" and "^2" or log_level == "warn" and "^3" or "^1"
Expand All @@ -17,7 +17,7 @@ local function send_http_request(data)
return
end
end, "POST", json.encode(data), {
["Authorization"] = API_KEY,
["Authorization"] = LOGS_API_KEY,
["Content-Type"] = "application/json",
})
end
Expand Down Expand Up @@ -61,14 +61,15 @@ function Process_Log_Request(log_level, message, metadata, resource)
-- might have to look into some batching later, in order to reduce the amount of requests sent to the backend
-- for testing though, this should be fine

if not API_KEY then
if not LOGS_API_KEY then
print("API key is not set, skipping log...")
return
end

send_http_request({
level = _log_level,
message = message,
resource = resource,
metadata = _metadata,
})
end
Expand Down
14 changes: 10 additions & 4 deletions shared/init.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
IS_SERVER = IsDuplicityVersion()
API_KEY = nil
LOGS_API_KEY = nil
MEDIA_API_KEY = nil

-- TODO: dont crash, just save data and resend later

if IS_SERVER then
math.randomseed(os.time())

API_KEY = GetConvar("FIVEMANAGE_API_KEY", "")
MEDIA_API_KEY = GetConvar("FIVEMANAGE_MEDIA_API_KEY", "")
LOGS_API_KEY = GetConvar("FIVEMANAGE_LOGS_API_KEY", "")

if API_KEY == "" then
error("FIVEMANAGE_API_KEY is not set, please set it before starting this resource!")
if MEDIA_API_KEY == "" then
error("FIVEMANAGE_MEDIA_API_KEY is not set, please set it before starting this resource!")
end

if LOGS_API_KEY == "" then
error("FIVEMANAGE_LOGS_API_KEY is not set. Logs to Fivemanage will not work without this key.")
end
end

Expand Down

0 comments on commit cfc35e0

Please sign in to comment.