summaryrefslogtreecommitdiff
path: root/dir.html
blob: d3c84d6508de89e2791a7563765668b5f6e23274 (plain)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<!DOCTYPE html>
<html>
  <head>
    {{if .Name}}<title>{{ .Name }}</title>{{end}}
  </head>
  <body>
<h1>🦄 Index of {{ .Name }} 🌈</h1><br>
<section id="main">
<table>
  <tbody>
    {{range .ListFiles}}
      <tr><td><a href="{{ .Path | formatURL }}">{{ .Name }}</a></td><td>{{ .Size | formatSize }}</td></tr>
    {{end}}
  </tbody>
</table>
</section>
<section id="nav">
  <h2>List of directories</h2>
<table>
  <tbody>
  {{range .ListCols}}
    <tr><td><a href="{{ .Path }}">{{ .Name }}</a></td></tr>
  {{end}}
</table>
</section>
<section id="dav">
  <div class="uploadDiv">
    <label for="fileinput">Envoyer un fichier : </label><br/>
    <input id="fileinput" type="file">
  </div>
  <hr/>
  <div class="moveDiv">
    <label for="file_move1">Déplaçer : </label><br/>
    <input id="file_move1" type="input"> <br/>
    <label for="file_move2">Vers : <br/>
    <input id="file_move2" type="input">
  </div>
  <hr/>
  <div class="mkdirDiv">
    <label for="mkcol_input">Créer un dossier : </label><br/>
    <input id="mkcol_input" type="input">
  </div>
  <hr/>
  <div class="repDiv">
    Réponse du server :
    <div id="bodyServResponse"><div>
  </div>

</section>
<div id="footer">Create with love 💟 bye <a href="https//ache.one">ache</a></div>
<script language="javascript">
const input = document.getElementById('fileinput');

const upload = (file) => {
  const l = window.location;

  let uri = l.protocol + '//' + l.hostname;
  if( l.port !== '80' ) {
    uri += ':' + l.port
  }
  uri += l.pathname

  console.log(uri)

  if( uri[uri.length - 1] !== '/' ) {
    uri += '/'
  }

  uri += file.name

  console.log(uri)

  fetch( encodeURI(uri) , {
    method: 'PUT',
    headers: {
      "Content-Type": file.type
    },
    body: file // This is your file object
  }).then(
    response => {
      console.log(response);
    }
  ).then(
    success => {
      console.log(success);
    }
  ).catch(
    error => {
      console.log(error);
    }
  );
};

const onSelectFile = () => {
  let i = 0;
  for( ; i < input.files.length ; i++) {
    upload(input.files[i]);
  }
};

const deleteMethode = (url, th) => {
  fetch( url , {
    method: 'DELETE',
  }).then(
    response => {
      console.log(response);
    }
  ).then(
    success => {
      if( th ) th.parentNode.removeChild(th)
      console.log(success);
    }
  ).catch(
    error => {
      console.log(error);
    }
  );
};

const onPageLoad = () => {
  const as = Array.from(document.getElementsByTagName('a'));

  as.filter( e => e.parentNode.parentNode.tagName == "TR").forEach( e => {
    const aFill = document.createElement('a');
    const a = document.createElement('a');
    const td = document.createElement('td');
    const moveInput = document.getElementById('file_move1');
    a.appendChild(document.createTextNode('🗙'));
    aFill.appendChild(document.createTextNode('↩'));
    a.classList.add('delete');
    aFill.classList.add('fill');
    a.href = "#";
    aFill.href = "#";
    a.onclick = () => false;
    aFill.onclick = () => false;
    td.appendChild(aFill);
    td.appendChild(a);
    a.addEventListener('click', () => {
      deleteMethode('/' + e.href.split('/').slice(3).join('/'), e.parentNode.parentNode)
      return false;
    }, false);
    aFill.addEventListener('click', () => {
      moveInput.value = e.href.split('/').slice(3).join('/');
    }, false);

    e.parentNode.parentNode.appendChild(td);
  });
}

input.addEventListener('change', onSelectFile, false);
window.addEventListener('load', onPageLoad, false);
</script>
<style>
body {
  display: grid;
  grid-template-columns: calc(100% / 5) calc(100% / 2.5 + 100% / 5 ) calc(100%/5);
  grid-template-areas: "h h h"
                       "nav  main dav"
                       "nav  f f";
}

h1 {
  grid-area: h;
}
#nav {
  grid-area: nav;
  background-color: #ffa0fc;
  margin: 1%;
}
#nav table {
  margin: 20px;
}

#main {
  grid-area: main;
  background-color: #00ff64;
  margin: 1%;
}
#main table {
  margin: 20px;
}
#dav {
  grid-area: dav;
  background-color: #33CCDD;
  margin: 1%;
}
#dav .uploadDiv, .mkdirDiv, .moveDiv, .repDiv {
  margin: 20px;
}
#bodyServResponse {
  text-indent: 5%;
  color: white;
}

#footer {
  grid-area: f;
  background-color: #fcffa0;
}
.delete {
  color: red;
}
.delete:hover {
  color: #3b4045;
  text-decoration: none;
}
</style>
</body>
</html>