Skip to content

Commit

Permalink
chore: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
itschip committed Jan 29, 2025
1 parent ba56b26 commit e0cdd76
Showing 1 changed file with 61 additions and 32 deletions.
93 changes: 61 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ScreenCapture (WIP)
# ScreenCapture

ScreenCapture is a being built as a replacement for screenshot-basic in FiveM.

Expand All @@ -17,7 +17,7 @@ Converting Base64 to Blob/Buffer is easy enough with Node, but Lua ScRT in FiveM
### serverCapture (server-side export)

| Parameter | Type | Description |
|------------|--------------------------|---------------------------------------------------------------------------|
| ---------- | ------------------------ | ------------------------------------------------------------------------- |
| `source` | string | Player to capture |
| `options` | object/table | Configuration options for the capture |
| `callback` | function | A function invoked with the captured data |
Expand All @@ -27,13 +27,12 @@ Converting Base64 to Blob/Buffer is easy enough with Node, but Lua ScRT in FiveM

The `options` argument accepts an object with the following fields:

| Field | Type | Default | Description |
|--------------|-----------------|----------|--------------------------------------------------------------------------|
| `headers` | `object/table` | `null` | Optional HTTP headers to include in the capture request. |
| `formField` | `string` | `null` | The form field name to be used when uploading the captured data. |
| `filename` | `string` | `null` | Specifies the name of the file when saving or transmitting captured data.|
| `encoding` | `string` | `'webp'` | Specifies the encoding format for the captured image (e.g., `'webp'`). |

| Field | Type | Default | Description |
| ----------- | -------------- | -------- | ------------------------------------------------------------------------- |
| `headers` | `object/table` | `null` | Optional HTTP headers to include in the capture request. |
| `formField` | `string` | `null` | The form field name to be used when uploading the captured data. |
| `filename` | `string` | `null` | Specifies the name of the file when saving or transmitting captured data. |
| `encoding` | `string` | `'webp'` | Specifies the encoding format for the captured image (e.g., `'webp'`). |

```ts
RegisterCommand(
Expand All @@ -57,39 +56,50 @@ RegisterCommand(

### remoteUpload (server-side export)

| Parameter | Type | Description |
|------------|--------------------------|---------------------------------------------------------------------------|
| `source` | string | Player to capture |
| `url` | string | The upload URL |
| `options` | object/table | Configuration options for the capture |
| `callback` | function | Callback returning the HTTP response in JSON |
| `dataType` | string (default: base64) | What data type should be used to upload the file: `'base64'` or `'blob'` |
| Parameter | Type | Description |
| ---------- | ------------------------ | ------------------------------------------------------------------------ |
| `source` | string | Player to capture |
| `url` | string | The upload URL |
| `options` | object/table | Configuration options for the capture |
| `callback` | function | Callback returning the HTTP response in JSON |
| `dataType` | string (default: base64) | What data type should be used to upload the file: `'base64'` or `'blob'` |

#### Options

The `options` argument accepts an object with the following fields:

| Field | Type | Default | Description |
|--------------|-----------------|----------|--------------------------------------------------------------------------|
| `headers` | `object/table` | `null` | Optional HTTP headers to include in the capture request. |
| `formField` | `string` | `null` | The form field name to be used when uploading the captured data. |
| `filename` | `string` | `null` | Specifies the name of the file when saving or transmitting captured data.|
| `encoding` | `string` | `'webp'` | Specifies the encoding format for the captured image (e.g., `'webp'`). |
| Field | Type | Default | Description |
| ----------- | -------------- | -------- | ------------------------------------------------------------------------- |
| `headers` | `object/table` | `null` | Optional HTTP headers to include in the capture request. |
| `formField` | `string` | `null` | The form field name to be used when uploading the captured data. |
| `filename` | `string` | `null` | Specifies the name of the file when saving or transmitting captured data. |
| `encoding` | `string` | `'webp'` | Specifies the encoding format for the captured image (e.g., `'webp'`). |

```ts
RegisterCommand("remoteCapture", (_: string, args: string[]) => {
exp.screencapture.remoteUpload(args[0], "https://api.fivemanage.com/api/image", {
encoding: "webp",
headers: {
"Authorization": "",
}
}, (data: any) => {
console.log(data);
}, "blob")
}, false);
RegisterCommand(
'remoteCapture',
(_: string, args: string[]) => {
exp.screencapture.remoteUpload(
args[0],
'https://api.fivemanage.com/api/image',
{
encoding: 'webp',
headers: {
Authorization: '',
},
},
(data: any) => {
console.log(data);
},
'blob',
);
},
false,
);
```

## Lua example with `remoteUpload`

```lua
exports.screencapture:remoteUpload(args[1], "https://api.fivemanage.com/api/image", {
encoding = "webp",
Expand All @@ -101,8 +111,27 @@ exports.screencapture:remoteUpload(args[1], "https://api.fivemanage.com/api/imag
end, "blob")
```

## Screenshot Basic compatibility

### This is NOT recommend to use, as you risk expsoing tokens to clients.

### requestScreenshotUpload (client-side export)

```lua
exports['screencapture']:requestScreenshotUpload('https://api.fivemanage.com/api/image', 'file', {
headers = {
["Authorization"] = API_TOKEN
},
encoding = "webp"
}, function(data)
local resp = json.decode(data)
print(resp.url);
TriggerEvent('chat:addMessage', { template = '<img src="{0}" style="max-width: 300px;" />', args = { resp.url } })
end)
```

## What will this include?

1. Server exports both for getting image data and uploading images/videos from the server
2. Client exports (maybe)
3. Upload images or videos from NUI, just more secure.
Expand Down

0 comments on commit e0cdd76

Please sign in to comment.