-
Notifications
You must be signed in to change notification settings - Fork 0
/
deleteVideo.php
109 lines (94 loc) · 2.97 KB
/
deleteVideo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
session_start();
require 'vendor/autoload.php';
use Aws\S3\S3Client;
use Aws\Exception\AwsException;
$videoId = $_GET['videoId'];
$serverStr = $_SESSION['currentServer'];
$folderId = $_SESSION['currentId'];
$bucket = $serverStr.'-vid';
$userFolder = $bucket.'/'.$folderId;
if (isset($_POST['yes'])) {
$dbHost = getenv('RDS_HOSTNAME');
$dbUser = getenv('RDS_USERNAME');
$dbPass = getenv('RDS_PASSWORD');
$dbConn = 'mysql:host='.$dbHost.';dbname='.$serverStr.';charset=utf8mb4';
try{
$conn = new \PDO( $dbConn,
$dbUser,
$dbPass,
array(
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_PERSISTENT => false
)
);
$dbHandle = $conn->prepare("DELETE from video where Id = ?");
$dbHandle->bindParam(1, $videoId, PDO::PARAM_STR);
$dbHandle->execute();
$likeHandle = $conn->prepare("DELETE from likes where videoId = ?");
$likeHandle->bindParam(1, $videoId, PDO::PARAM_STR);
$likeHandle->execute();
$s3Client = new \Aws\S3\S3Client([
'version' => 'latest',
'region' => 'ca-central-1'
]);
$s3Client->registerStreamWrapper();
$s3Protocol = 's3://'.$userFolder.'/'.$videoId;
unlink($s3Protocol);
//need to find way to delete an object
} catch(\PDOException $ex){
print($ex->getMessage());
}
echo "<script>window.close();</script>";
} else if(isset($_POST['no'])){
echo "<script>window.close();</script>";
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>LeagueLights Delete Video</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/shop-homepage.css" rel="stylesheet">
<link href="css/leaguelights.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<div class="container">
<p class="navbar-brand">LeagueLights</p>
</div>
</nav>
<div class="container py-5">
<div class="row my-4">
<div class="col-lg-3"></div>
<form method="post" class="col-lg-6">
<div class="row">
<div class="col-lg-3"></div>
<h4 class="text-center col-lg-6">Do you want to delete the video? All likes on this video will be deleted as well.</p>
<div class="col-lg-3"></div>
</div>
<div class="row">
<div class="col-lg-2"></div>
<button class="col-lg-3" type="submit" name="yes" value="yes">Yes</button>
<div class="col-lg-2"></div>
<button class="col-lg-3" type="submit" name="no" value="no">No</button>
<div class="col-lg-2"></div>
</div>
</form>
<div class="col-lg-3"></div>
</div>
</div>
<script>
window.onunload = refreshParent;
function refreshParent() {
window.opener.location.reload();
}
</script>
</body>
</html>