Skip to content
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
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
**/dist
**/app/launcher/dist/dev_mode_launcher/_internal
releases
temp.txt

# Compiled Scripts
**/utils/reload/*.js
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Github Video Compressor

[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

## Description

A inline video compressor for Github PR.
Never see the 100MB upload video file limit on Github PRs again.

## Table of Contents

- [Installation](#installation)
- [Contributing](#contributing)
- [License](#license)

## App + Extension Installation

TBD

## Contributing

TBD

## License

This project is licensed under the [MIT License](LICENSE).
2 changes: 1 addition & 1 deletion app/electron-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
},

dmg: {
icon: true,
icon: false,
},

linux: {
Expand Down
2 changes: 1 addition & 1 deletion app/launcher/dev_mode_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def start_subprocess(ws):
global proc
current_directory = os.path.dirname(os.path.realpath(__file__))
project_root = find_project_root(current_directory, '.github')
electron_path = os.path.join(project_root, "node_modules/electron/dist/Electron.app/Contents/MacOS/Electron")
electron_path = os.path.join(project_root, "app/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron")
main_script_path = os.path.join(project_root, "app/node_modules/.dev/main/index.js")

# Set environment variables for the subprocess
Expand Down
Binary file modified app/launcher/dist/dev_mode_launcher/dev_mode_launcher
Binary file not shown.
25 changes: 15 additions & 10 deletions app/src/main/dev_websockets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import WebSocket from 'ws'

const debugWebSocket = new WebSocket('ws://localhost:3333')
let debugWebSocket: WebSocket | null = null

function generateRandomClientId() {
const colors = ['red', 'blue', 'green', 'yellow', 'pink', 'black', 'white', 'purple', 'orange', 'brown']
Expand All @@ -9,10 +9,23 @@ function generateRandomClientId() {
const animal = animals[Math.floor(Math.random() * animals.length)]
return `${color} ${animal}`
}

const clientId = generateRandomClientId()

export const initWebSocketServer = () => {
debugWebSocket = new WebSocket('ws://localhost:3333')

debugWebSocket.on('open', function open() {
sendDebugMessage('info', 'Connected to debug server')
})

debugWebSocket.on('close', function close() {
sendDebugMessage('info', 'Disconnected from debug server')
})
}

export function sendDebugMessage(type: string, data: string | Record<string, any> | null) {
if (!debugWebSocket) return

const message = {
type: type,
client_id: clientId,
Expand All @@ -29,11 +42,3 @@ export function sendDebugMessage(type: string, data: string | Record<string, any
}, 2000)
}
}

debugWebSocket.on('open', function open() {
sendDebugMessage('info', 'Connected to debug server')
})

debugWebSocket.on('close', function close() {
sendDebugMessage('info', 'Disconnected from debug server')
})
8 changes: 6 additions & 2 deletions app/src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { app } from 'electron'

// import { sendDebugMessage } from 'main/dev_websockets'
import { sendDebugMessage } from 'main/dev_websockets'
import { initWebSocketServer, sendDebugMessage } from 'main/dev_websockets'
import { generateToken } from 'shared/utils/crypto.util'
import { startHttpFileServer } from 'shared/utils/httpFileServer'
import { NativeMessagingHost } from 'shared/utils/nativeMessagingHost'
Expand All @@ -14,8 +14,13 @@ const port = 7777
makeAppWithSingleInstanceLock(async () => {
await app.whenReady()

const isDev = process.argv.includes('--development')

try {
const nativeMessagingHost = new NativeMessagingHost()
if (isDev) {
initWebSocketServer()
}
const { server } = startHttpFileServer(app, port)

nativeMessagingHost.addListener(message => {
Expand Down Expand Up @@ -49,6 +54,5 @@ makeAppWithSingleInstanceLock(async () => {
// @ts-ignore
sendDebugMessage('error', e?.message || 'unknown')
app.quit()
console.error('app error:', e)
}
})
1 change: 0 additions & 1 deletion app/src/shared/utils/httpFileServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export const startHttpFileServer = (electronApp: Electron.App, port: number = 77

sendDebugMessage('debug - name', req.file.originalname)
sendDebugMessage('debug - path', req.file.path)
sendDebugMessage('debug - upload input path', fs.readdirSync('uploads').join(', '))
// @ts-expect-error -- test token
sendDebugMessage('debug - token', req?.token)
sendDebugMessage('debug - file', req.file)
Expand Down
44 changes: 23 additions & 21 deletions extension/src/pages/content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ const fileSizeToMB = fileSize => {
// Iterate over the FileList
for (let i = 0; i < files.length; i++) {
const file = files.item(i)

// Ignore files that are small
if (file.size < TRIGGER_SIZE) return

if (!file) {
throw new Error('file not found')
}
Expand All @@ -269,28 +273,26 @@ const fileSizeToMB = fileSize => {
e.stopPropagation()
e.preventDefault()

if (file.size > TRIGGER_SIZE) {
displayLoadingWithSpinner(textAreaElement, `Compressing [${file.name}]`)
execCommand('compress_file', {
file,
displayLoadingWithSpinner(textAreaElement, `Compressing [${file.name}]`)
execCommand('compress_file', {
file,
})
.then(({ file: compressedFile }) => {
console.log('compressedFile', compressedFile)
console.log('finish compressed video')
if (compressedFile) {
updateLoadingText(
textAreaElement,
`Compressing [${file.name}]`,
`Uploading [${compressedFile.name}]`,
)

uploadFile(textAreaElement, compressedFile, compressedFile.name)
}
})
.catch(err => {
console.log('err', err)
})
.then(({ file: compressedFile }) => {
console.log('compressedFile', compressedFile)
console.log('finish compressed video')
if (compressedFile) {
updateLoadingText(
textAreaElement,
`Compressing [${file.name}]`,
`Uploading [${compressedFile.name}]`,
)

uploadFile(textAreaElement, compressedFile, compressedFile.name)
}
})
.catch(err => {
console.log('err', err)
})
}
}
}
}
Expand Down