Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #352 from mgilangjanuar/staging
Browse files Browse the repository at this point in the history
patch1
  • Loading branch information
mgilangjanuar authored May 11, 2022
2 parents a5e5256 + 0993bb3 commit bb19df9
Show file tree
Hide file tree
Showing 32 changed files with 5,865 additions and 16 deletions.
2 changes: 1 addition & 1 deletion android/Teledrive-Expo/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function App() {
return (
<WebView
style={styles.container}
source={{ uri: 'https://androidteledrive.herokuapp.com'}}
source={{ uri: 'https://teledrive-web.vercel.app/startup'}}
/>
);
}
Expand Down
8 changes: 5 additions & 3 deletions android/Teledrive-Expo/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"expo": {
"name": "Teledrive",
"slug": "snack-6b33518d-2b5e-46c5-beb5-d37aa4f26f80",
"version": "1.0.0",
"version": "1.0.2",
"orientation": "portrait",
"icon": "./assets/icon.png",
"splash": {
Expand All @@ -20,13 +20,15 @@
"supportsTablet": true
},
"android": {
"versionCode": 3,
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
}
},
"package": "com.mgilangjanuar.teledrive"
},
"web": {
"favicon": "./assets/favicon.png"
}
}
}
}
18 changes: 18 additions & 0 deletions android/Teledrive-Expo/eas.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"cli": {
"version": ">= 0.52.0"
},
"build": {
"development": {
"developmentClient": true,
"distribution": "internal"
},
"preview": {
"distribution": "internal"
},
"production": {}
},
"submit": {
"production": {}
}
}
5,511 changes: 5,511 additions & 0 deletions android/Teledrive-Expo/yarn.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
"nanoid": "^3.1.25",
"pg": "^8.7.1",
"pg-connection-string": "^2.5.0",
"prisma": "^3.14.0",
"redis": "^4.0.1",
"serialize-error": "^8.1.0",
"serverless-http": "^3.0.1",
"source-map-support": "^0.5.19",
"teledrive-client": "^2.7.23",
"uuid-random": "^1.3.2"
Expand Down Expand Up @@ -76,7 +78,6 @@
"@typescript-eslint/parser": "^4.29.3",
"eslint": "^7.32.0",
"nodemon": "^2.0.12",
"prisma": "^3.14.0",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"typescript": "^4.4.2"
Expand Down
35 changes: 25 additions & 10 deletions api/src/api/v1/Files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,8 @@ export class Files {

const readStream = createReadStream(filename(), { start, end })
res.writeHead(206, {
'Cache-Control': 'public, max-age=604800',
'ETag': Buffer.from(`${files[0].id}:${files[0].message_id}`).toString('base64'),
'Content-Range': `bytes ${start}-${end}/${totalFileSize}`,
'Content-Disposition': contentDisposition(files[0].name.replace(/\.part\d+$/gi, ''), { type: Number(dl) === 1 ? 'attachment' : 'inline' }),
'Content-Type': files[0].mime_type,
Expand All @@ -1016,6 +1018,8 @@ export class Files {
readStream.pipe(res)
} else {
res.writeHead(206, {
'Cache-Control': 'public, max-age=604800',
'ETag': Buffer.from(`${files[0].id}:${files[0].message_id}`).toString('base64'),
'Content-Range': `bytes */${totalFileSize}`,
'Content-Disposition': contentDisposition(files[0].name.replace(/\.part\d+$/gi, ''), { type: Number(dl) === 1 ? 'attachment' : 'inline' }),
'Content-Type': files[0].mime_type,
Expand All @@ -1030,14 +1034,20 @@ export class Files {
return
}

res.setHeader('Cache-Control', 'public, max-age=604800')
res.setHeader('ETag', Buffer.from(`${files[0].id}:${files[0].message_id}`).toString('base64'))
res.setHeader('Content-Range', `bytes */${totalFileSize}`)
res.setHeader('Content-Disposition', contentDisposition(files[0].name.replace(/\.part\d+$/gi, ''), { type: Number(dl) === 1 ? 'attachment' : 'inline' }))
res.setHeader('Content-Type', files[0].mime_type)
res.setHeader('Content-Length', totalFileSize.toString())
res.setHeader('Accept-Ranges', 'bytes')

let downloaded: number = 0
writeFileSync(filename('process-'), '')
try {
writeFileSync(filename('process-'), '')
} catch (error) {
// ignore
}

for (const file of files) {
let chat: any
Expand Down Expand Up @@ -1068,21 +1078,26 @@ export class Files {
if (cancel) {
throw { status: 422, body: { error: 'canceled' } }
} else {
// if (downloaded > start) {
// return res.end()
// }
console.log(`${chat['messages'][0].id} ${downloaded}/${chat['messages'][0].media.document.size} (${downloaded/Number(chat['messages'][0].media.document.size)})`)
appendFileSync(filename('process-'), buffer)
try {
appendFileSync(filename('process-'), buffer)
} catch (error) {
// ignore
}
res.write(buffer)
}
},
close: () => {
console.log(`${chat['messages'][0].id} ${downloaded}/${chat['messages'][0].media.document.size} (${downloaded/Number(chat['messages'][0].media.document.size)})`, '-end-')
const { size } = statSync(filename('process-'))
if (totalFileSize.gt(bigInt(size))) {
rmSync(filename('process-'))
} else {
renameSync(filename('process-'), filename())
try {
const { size } = statSync(filename('process-'))
if (totalFileSize.gt(bigInt(size))) {
rmSync(filename('process-'))
} else {
renameSync(filename('process-'), filename())
}
} catch (error) {
// ignore
}
res.end()
}
Expand Down
6 changes: 5 additions & 1 deletion api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import listEndpoints from 'express-list-endpoints'
import morgan from 'morgan'
import path from 'path'
import { serializeError } from 'serialize-error'
import serverless from 'serverless-http'
import { API } from './api'
import { Redis } from './service/Cache'
import { markdownSafe } from './utils/StringParser'
Expand Down Expand Up @@ -98,4 +99,7 @@ app.use((req: Request, res: Response) => {

app.listen(process.env.PORT || 4000, () => console.log(`Running at :${process.env.PORT || 4000}...`))

console.log(listEndpoints(app))
console.log(listEndpoints(app))

module.exports = app
module.exports.handler = serverless(app)
13 changes: 13 additions & 0 deletions electron/.github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
ignore:
- dependency-name: electron
versions:
- 11.2.1
- 11.2.2
- 12.0.0
4 changes: 4 additions & 0 deletions electron/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
release-builds
package-lock.json
.DS_Store
10 changes: 10 additions & 0 deletions electron/assets/css/no-topbar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* No topbar */

#webview {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: inline-flex !important;
}
8 changes: 8 additions & 0 deletions electron/assets/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* Main */

body {
margin: 0;
padding: 0;
-webkit-user-select: none;
-webkit-app-region: drag;
}
7 changes: 7 additions & 0 deletions electron/assets/css/topbar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* Topbar */

#controls {
padding: 5px;
border-bottom: solid 1px #ccc;
background-color: #f8f8f8;
}
Binary file added electron/assets/icons/mac/icon.icns
Binary file not shown.
Binary file added electron/assets/icons/png/128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added electron/assets/icons/png/16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added electron/assets/icons/png/24x24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added electron/assets/icons/png/256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added electron/assets/icons/png/32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added electron/assets/icons/png/48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added electron/assets/icons/png/512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added electron/assets/icons/png/64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added electron/assets/icons/png/96x96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added electron/assets/icons/win/icon.ico
Binary file not shown.
32 changes: 32 additions & 0 deletions electron/assets/js/renderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const getControlsHeight = () => {
const controls = document.querySelector("#controls");
if (controls) {
return controls.offsetHeight;
}
return 0;
};

function calculateLayoutSize() {
const webview = document.querySelector("webview");
const windowWidth = document.documentElement.clientWidth;
const windowHeight = document.documentElement.clientHeight;
const controlsHeight = getControlsHeight();
const webviewHeight = windowHeight - controlsHeight;

webview.style.width = windowWidth + "px";
webview.style.height = webviewHeight + "px";
}

const homeButton = () => {
document.querySelector("#home").onclick = () => {
const home = document.getElementById("webview").getAttribute("data-home");
document.querySelector("webview").src = home;
};
};

window.onload = () => {
calculateLayoutSize();
homeButton();
};

window.onresize = calculateLayoutSize;
31 changes: 31 additions & 0 deletions electron/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<html>
<head>
<link rel="stylesheet" href="assets/css/style.css" />
<link rel="stylesheet" href="assets/css/topbar.css" />
<!-- <link rel="stylesheet" href="assets/css/no-topbar.css"> -->
<script defer src="assets/js/renderer.js"></script>
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self'; style-src 'self' 'unsafe-inline';"
/>
</head>
<body>
<!-- Topbar -->
<div id="controls">
<button id="home" title="Go Home">Home</button>

</div>
<!-- End topbar -->

<!-- Webview -->
<webview
id="webview"
autosize="on"
src="https://teledrive-web.vercel.app/startup"
data-home="https://teledrive-web.vercel.app/startup"
></webview>



</body>
</html>
38 changes: 38 additions & 0 deletions electron/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Electron
const { app, Menu } = require("electron");
const remoteMain = require("@electron/remote/main");
remoteMain.initialize();

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.allowRendererProcessReuse = true;
app.on("ready", () => {
// Main window
const window = require("./src/window");
mainWindow = window.createBrowserWindow(app);
remoteMain.enable(mainWindow.webContents);

// Option 1: Uses Webtag and load a custom html file with external content
mainWindow.loadURL(`file://${__dirname}/index.html`);

// Option 2: Load directly an URL if you don't need interface customization
//mainWindow.loadURL("https://github.com");

// Option 3: Uses BrowserView to load an URL
//const view = require("./src/view");
//view.createBrowserView(mainWindow);

// Display Dev Tools
//mainWindow.openDevTools();

// Menu (for standard keyboard shortcuts)
const menu = require("./src/menu");
const template = menu.createTemplate(app.name);
const builtMenu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(builtMenu);
});

// Quit when all windows are closed.
app.on("window-all-closed", () => {
app.quit();
});
31 changes: 31 additions & 0 deletions electron/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "electron-webview",
"productName": "Electron webview",
"version": "1.0.0",
"description": "A simple Electron webview application",
"main": "main.js",
"scripts": {
"start": "electron .",
"package-mac": "electron-packager . --overwrite --platform=darwin --arch=x64 --icon=assets/icons/mac/icon.icns --prune=true --out=release-builds",
"package-win": "electron-packager . --overwrite --asar=true --platform=win32 --arch=ia32 --icon=assets/icons/win/icon.ico --prune=true --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName=\"Electron Webview\"",
"package-linux": "electron-packager . --overwrite --platform=linux --arch=x64 --icon=assets/icons/png/1024x1024.png --prune=true --out=release-builds",
"create-installer-mac": "electron-installer-dmg ./release-builds/Electron\\ webview-darwin-x64/Electron\\ webview.app electron-webview --out=release-builds --overwrite --icon=assets/icons/mac/icon.icns"
},
"repository": "https://github.com/cba85/electron-webview",
"keywords": [
"Electron",
"webview",
"tutorial",
"demo"
],
"author": "GitHub",
"license": "MIT",
"dependencies": {
"@electron/remote": "^2.0.0"
},
"devDependencies": {
"electron": "^18.0.0",
"electron-installer-dmg": "^3.0.0",
"electron-packager": "^15.5.1"
}
}
15 changes: 15 additions & 0 deletions electron/preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { BrowserWindow } = require("@electron/remote");

window.addEventListener("DOMContentLoaded", () => {
// Print function
document.getElementById("print_button").addEventListener("click", () => {
const url = document.querySelector("webview").getAttribute("src");

let printWindow = new BrowserWindow({ "auto-hide-menu-bar": true });
printWindow.loadURL(url);

printWindow.webContents.on("did-finish-load", () => {
printWindow.webContents.print();
});
});
});
Loading

1 comment on commit bb19df9

@vercel
Copy link

@vercel vercel bot commented on bb19df9 May 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.