make popup window removed video token and cookie when it is closed. Fixed mobile context menu not being able to download files

This commit is contained in:
kyle hoell
2020-11-27 17:53:15 -05:00
parent 9dbddb244e
commit f6fbada5b1
6 changed files with 72 additions and 14 deletions
+29 -3
View File
@@ -3,10 +3,11 @@ import FileService from "../services/FileService";
import MongoService from "../services/ChunkService/MongoService";
import FileSystemService from "../services/ChunkService/FileSystemService";
import S3Service from "../services/ChunkService/S3Service";
import {UserInterface} from "../models/user";
import User, {UserInterface} from "../models/user";
import tempStorage from "../tempStorage/tempStorage";
import sendShareEmail from "../utils/sendShareEmail";
import { createStreamVideoCookie } from "../cookies/createCookies";
import { createStreamVideoCookie, removeStreamVideoCookie } from "../cookies/createCookies";
import { ObjectID } from "mongodb";
const fileService = new FileService()
@@ -24,7 +25,8 @@ interface RequestTypeRefresh extends Request {
interface RequestTypeFullUser extends Request {
user?: UserInterface,
encryptedToken?: string
encryptedToken?: string,
accessTokenStreamVideo?: string
}
interface RequestType extends Request {
@@ -356,6 +358,30 @@ class FileController {
}
removeStreamVideoAccessToken = async(req: RequestTypeFullUser, res: Response) => {
if (!req.user) return;
try {
const userID = req.user._id;
const accessTokenStreamVideo = req.accessTokenStreamVideo!;
await User.updateOne({_id: userID}, {$pull: {tempTokens: {token: accessTokenStreamVideo}}});
removeStreamVideoCookie(res);
res.send();
} catch (e) {
console.log("\Remove Video Token File Router Error:", e.message);
const code = !e.code ? 500 : e.code >= 400 && e.code <= 599 ? e.code : 500;
res.status(code).send();
}
}
// getDownloadTokenVideo = async(req: RequestTypeFullUser, res: Response) => {
// if (!req.user) {
+10
View File
@@ -46,4 +46,14 @@ export const createStreamVideoCookie = (res: Response, streamVideoAccessToken: s
sameSite: "strict",
secure: process.env.NODE_ENV === "production"
})
}
export const removeStreamVideoCookie = (res: Response) => {
res.cookie("video-access-token", {}, {
httpOnly: true,
maxAge: 0,
sameSite: "strict",
secure: process.env.NODE_ENV === "production"
})
}
+2
View File
@@ -57,6 +57,8 @@ router.get("/file-service/download/access-token-stream-video", authFullUser, fil
router.get("/file-service/stream-video/:id", authStreamVideo, fileController.streamVideo);
router.delete("/file-service/remove-stream-video-token", authStreamVideo, fileController.removeStreamVideoAccessToken);
//router.get("/file-service/stream-video/:id/:tempToken/:uuid", auth, fileController.streamVideo);
//router.get("/file-service/stream-video/:id", auth, fileController.streamVideo);
+2
View File
@@ -8,6 +8,7 @@ interface RequestType extends Request {
user?: UserInterface,
token?: string,
encryptedToken?: string,
accessTokenStreamVideo?: string
}
// type jwtType = {
@@ -84,6 +85,7 @@ const authStreamVideo = async(req: RequestType, res: Response, next: NextFunctio
if (!tokenFound) throw new Error("Refresh Token Not Found");
req.user = user;
req.accessTokenStreamVideo = encryptedToken;
next();
+25 -8
View File
@@ -79,14 +79,11 @@ class MobileContextMenuContainer extends React.Component {
this.props.dispatch(setLastSelected(0));
axios.get(currentURL +'/file-service/download/get-token')
.then((response) => {
const tempToken = response.data.tempToken;
axios.post("/user-service/get-token").then((response) => {
const finalUrl =
isGoogle ? !isGoogleDoc ? currentURL + `/file-service-google/download/${fileID}/${tempToken}` : currentURL + `/file-service-google-doc/download/${fileID}/${tempToken}`
: !isPersonal ? currentURL + `/file-service/download/${fileID}/${tempToken}` : currentURL + `/file-service-personal/download/${fileID}/${tempToken}`
isGoogle ? !isGoogleDoc ? currentURL + `/file-service-google/download/${fileID}` : currentURL + `/file-service-google-doc/download/${fileID}`
: !isPersonal ? currentURL + `/file-service/download/${fileID}` : currentURL + `/file-service-personal/download/${fileID}`
const link = document.createElement('a');
document.body.appendChild(link);
@@ -95,9 +92,29 @@ class MobileContextMenuContainer extends React.Component {
link.setAttribute("download", true);
link.click();
}).catch((err) => {
console.log(err)
}).catch((e) => {
console.log("Download file get refresh token error", e);
})
// axios.get(currentURL +'/file-service/download/get-token')
// .then((response) => {
// const tempToken = response.data.tempToken;
// const finalUrl =
// isGoogle ? !isGoogleDoc ? currentURL + `/file-service-google/download/${fileID}/${tempToken}` : currentURL + `/file-service-google-doc/download/${fileID}/${tempToken}`
// : !isPersonal ? currentURL + `/file-service/download/${fileID}/${tempToken}` : currentURL + `/file-service-personal/download/${fileID}/${tempToken}`
// const link = document.createElement('a');
// document.body.appendChild(link);
// link.href = finalUrl;
// link.setAttribute('type', 'hidden');
// link.setAttribute("download", true);
// link.click();
// }).catch((err) => {
// console.log(err)
// })
}
moveOnClick = () => {
+4 -3
View File
@@ -150,13 +150,14 @@ class PopupWindowContainer extends React.Component {
componentWillUnmount = () => {
const uuidID = window.sessionStorage.getItem("uuid");
document.removeEventListener('mousedown', this.handleClickOutside);
if (this.props.popupFile.metadata.isVideo) {
axios.delete(currentURL +`/file-service/remove/token-video/${this.tempToken}/${uuidID}`, {
axios.delete(`/file-service/remove-stream-video-token`).then(() => {
console.log("removed video access token");
}).catch((err) => {
console.log(err);
})