Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate Fivemerr into qb-phone #399

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1401,11 +1401,34 @@ RegisterNUICallback('TakePhoto', function(_, cb)
cb(json.encode({ url = nil }))
break
elseif IsControlJustPressed(1, 176) then -- TAKE.. PIC
if Config.Fivemerr == true then
-- Fivemerr uploads via the server using screenshot-basic to further guard your API key.
return QBCore.Functions.TriggerCallback('qb-phone:server:UploadToFivemerr', function(fivemerrData)
if fivemerrData == nil then
DestroyMobilePhone()
CellCamActivate(false, false)
takePhoto = false
return
end

SaveToInternalGallery()
local imageData = json.decode(fivemerrData)
DestroyMobilePhone()
CellCamActivate(false, false)
TriggerServerEvent('qb-phone:server:addImageToGallery', imageData.url)
Wait(400)
TriggerServerEvent('qb-phone:server:getImageFromGallery')
cb(json.encode(imageData.url))
takePhoto = false
end)
end

QBCore.Functions.TriggerCallback('qb-phone:server:GetWebhook', function(hook)
if not hook then
QBCore.Functions.Notify('Camera not setup', 'error')
return
end

exports['screenshot-basic']:requestScreenshotUpload(tostring(hook), 'files[]', function(data)
SaveToInternalGallery()
local image = json.decode(data)
Expand Down
5 changes: 5 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ Config.TweetDuration = 12 -- How many hours to load tweets (12 will load the pas
Config.RepeatTimeout = 2000
Config.CallRepeats = 10
Config.OpenPhone = 'M'

-- Set this to true if you wish to use Fivemerr (https://fivemerr.com/) for media uploads.
-- Ensure to add your API key to server/main.lua
Config.Fivemerr = false

Config.PhoneApplications = {
['phone'] = {
app = 'phone',
Expand Down
27 changes: 27 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local Calls = {}
local Adverts = {}
local GeneratedPlates = {}
local WebHook = ''
local FivemerrApiToken = 'API_KEY_HERE'
local bannedCharacters = { '%', '$', ';' }
local TWData = {}

Expand Down Expand Up @@ -591,6 +592,32 @@ QBCore.Functions.CreateCallback('qb-phone:server:GetWebhook', function(_, cb)
end
end)

QBCore.Functions.CreateCallback('qb-phone:server:UploadToFivemerr', function(source, cb)
local src = source

if Config.Fivemerr == '' then
print("^1--- Fivemerr is enabled but no API token has been specified. ---^7")
return cb(nil)
end

exports['screenshot-basic']:requestClientScreenshot(src, {
encoding = 'png'
}, function(err, data)
if err then return cb(nil) end
PerformHttpRequest(WebHook, function(status, response)
if status ~= 200 then
print("^1--- ERROR UPLOADING IMAGE: " .. status .. " ---^7")
cb(nil)
end

cb(response)
end, "POST", json.encode({ data = data }), {
['Authorization'] = FivemerrApiToken,
['Content-Type'] = 'application/json'
})
end)
end)

-- Events

RegisterNetEvent('qb-phone:server:AddAdvert', function(msg, url)
Expand Down
Loading