Skip to content

Commit

Permalink
Merge pull request #399 from DeeRock94/fivemerr-integration
Browse files Browse the repository at this point in the history
Integrate Fivemerr into qb-phone
  • Loading branch information
GhzGarage authored Nov 13, 2024
2 parents 007e5ee + fceb7d7 commit ffc7c05
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
23 changes: 23 additions & 0 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1389,11 +1389,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 @@ -609,6 +610,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

0 comments on commit ffc7c05

Please sign in to comment.