/
index.html
739 lines (660 loc) · 38.2 KB
/
index.html
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
<!DOCTYPE html>
<html ng-app="assetApp" ng-controller="assetController">
<head>
<title ng-bind="ngMeta.title">MC Assets - Browser for Minecraft Asset Files</title>
<link id="favicon" rel="shortcut icon" type="image/png" href="/favicon.png"/>
<meta name="description" content="MC Assets is a browser for Minecraft asset files. Explore all Textures, Sounds, Models, Fonts, Shaders, and more from any Minecraft version, without having to extract the files yourself">
<meta name="keywords" content="minecraft,assets,browser,explorer,textures,sounds,models,shaders,fonts,version,extract,resource">
<meta name="author" content="inventivetalent">
<meta property="og:type" content="website">
<meta property="og:title" content="{{ ngMeta['title'] || 'Minecraft Assets' }}">
<meta property="og:image" content="{{ ngMeta['image'] || 'https://mcasset.cloud/img/mc-assets-2-512.png' }}">
<meta property="og:description" content="MC Assets is a browser for Minecraft asset files. Explore all Textures, Sounds, Models, Fonts, Shaders, and more from any Minecraft version, without having to extract the files yourself">
<meta property="twitter:title" content="{{ ngMeta['title'] || 'Minecraft Assets' }}">
<meta property="twitter:image" content="{{ ngMeta['image'] || 'https://mcasset.cloud/img/mc-assets-2-512.png' }}">
<meta property="twitter:description" content="MC Assets is a browser for Minecraft asset files. Explore all Textures, Sounds, Models, Fonts, Shaders, and more from any Minecraft version, without having to extract the files yourself">
<meta property="twitter:creator" content="@Inventivtalent">
<meta property="twitter:card" content="summary">
<meta name="flattr:id" content="okelw0">
<meta name="robots" content="index, follow">
<link href="/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.1/css/all.css" integrity="sha384-O8whS3fhG2OnA5Kas0Y9l3cfpmYjapjI0E4theH4iuMD+pLhbf6JI0jIMfYcK3yZ" crossorigin="anonymous">
<meta name=viewport content="width=device-width, initial-scale=1">
<base href="/">
<style>
.list-group-item-file {
}
.list-group-item-dir {
background-color: #f9f9f9;
}
.far {
font-size: 18px;
}
</style>
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.js"></script>
<script>
window.addEventListener("load", function () {
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "#edeff5",
"text": "#838391"
},
"button": {
"background": "#4b81e8"
}
},
"position": "bottom-right"
})
});
</script>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-2604356629473365",
enable_page_level_ads: true
});
</script>
</head>
<body ng-cloak>
<a href="https://github.com/InventivetalentDev/mcasset.cloud" target="_blank">
<img style="position: absolute; top: 0; right: 0; border: 0;"
src="https://camo.githubusercontent.com/a6677b08c955af8400f44c6298f40e7d19cc5b2d/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677261795f3664366436642e706e67"
alt="Fork me on GitHub"
data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png">
</a>
<nav class="navbar navbar-default navbar-fixed-top" ng-show="asset.version && showNav" style="min-height: 40px; height: 50px;">
<div class="container" style="height:40px;padding:5px;">
<ol class="breadcrumb">
<a href="#" ng-if="asset.pathElements.length > 0" ng-click="goToPath(getJoinedPath(asset.pathElements.length-1))" style="padding-right: 6px;">
<i class="fa fa-arrow-left" aria-hidden="true"></i>
</a>
<li class="breadcrumb-item">
<a href="#" ng-click="goToPath('/')">
{{asset.version}}
</a>
</li>
<li class="breadcrumb-item" ng-repeat="element in asset.pathElements" ng-class="{'active': $last}">
<a href="#" ng-click="goToPath(getJoinedPath($index+1))">
{{element}}
</a>
</li>
<span class="pull-right" ng-show="assetIndex">{{ assetIndex.length }} Files</span>
</ol>
</div>
</nav>
<div class="container-fluid" style="margin-bottom: 100px;">
<div class="jumbotron">
<div class="container">
<div class="row">
<div class="col-md-2">
<img src="/img/mc-assets-2-256.png" class="img-responsive">
</div>
<div class="col-md-10">
<h1>Minecraft Assets</h1>
</div>
</div>
<br/>
<div class="row">
<div class="col-md-12">
<p>
A Browser for Minecraft Asset Files!<br/>
Explore all <strong>Textures, Sounds, Models, Fonts, Shaders, and more</strong> from any Minecraft version, without having to extract the files yourself
</p>
</div>
</div>
</div>
</div>
<div class="container">
<div>
<div ng-show="versions.versions.length > 0">
<h4>Minecraft Version</h4>
<div class="form-group">
<label class="col-lg-2 control-label" for="inputVersion">
<strong>Minecraft Version</strong>
</label>
<div class="col-lg-10">
<select id="inputVersion" ng-model="asset.version" class="form-control" ng-change="versionChanged()">
<option value="" disabled selected>Please select a Minecraft Version</option>
<optgroup label="Releases">
<option ng-repeat="version in versions.versions" ng-if="version.type==='release'" value="{{version.id}}">{{version.id + (version.id === versions.latest.release ? " (latest)" : "")}}</option>
</optgroup>
<optgroup label="Snapshots">
<option ng-repeat="version in versions.versions" ng-if="version.type==='snapshot'" value="{{version.id}}">{{version.id + (version.id === versions.latest.snapshot ? " (latest)" : "")}}</option>
</optgroup>
<optgroup label="Old Beta" ng-if="showOldVersions">
<option ng-repeat="version in versions.versions" ng-if="showOldVersions && version.type==='old_beta'">{{version.id}}</option>
</optgroup>
<optgroup label="Old Alpha" ng-if="showOldVersions">
<option ng-repeat="version in versions.versions" ng-if="showOldVersions && version.type==='old_alpha'">{{version.id}}</option>
</optgroup>
</select>
</div>
</div>
<!--
<div class="form-group">
<div class="col-lg-2">
</div>
<div class="col-lg-10">
<input type="checkbox" ng-model="showOldVersions">
<label>Include old versions (beta/alpha)</label>
</div>
</div>
-->
</div>
<div ng-hide="versions.versions.length > 0">
<img src="img/loading.svg">
<strong>Loading Versions...</strong>
</div>
</div>
<br/>
<br/>
<div>
<div ng-show="asset.version">
<h4>Browse Files</h4>
<ol class="breadcrumb">
<a href="#" ng-if="asset.pathElements.length > 0" ng-click="goToPath(getJoinedPath(asset.pathElements.length-1))" style="padding-right: 6px;">
<i class="fa fa-arrow-left" aria-hidden="true"></i>
</a>
<li class="breadcrumb-item">
<a href="#" ng-click="goToPath('/')">
{{asset.version}}
</a>
</li>
<li class="breadcrumb-item" ng-repeat="element in asset.pathElements" ng-class="{'active': $last}">
<a href="#" ng-click="goToPath(getJoinedPath($index+1))">
{{element}}
</a>
</li>
<span class="pull-right" ng-show="assetIndex">{{ assetIndex.length }} Files</span>
</ol>
<div ng-show="assetIndex.length > 0" style="margin-bottom: 20px;">
<ul class="list-group">
<li class="list-group-item" ng-repeat="file in assetIndex" ng-class="{'list-group-item-dir': file.type==='dir'}">
<a href="{{ asset.version + '/' + file.path }}" ng-click="file.type==='dir' ? goToPath(file.path, $event) : openFile(file, $event)">
<i class="far fa-folder" aria-hidden="true" ng-if="file.type==='dir'"></i>
<i class="far fa-file" aria-hidden="true" ng-if="file.type==='file' && !isJsonFile(file.name) && !isImageFile(file.name) && !isAudioFile(file.name)"></i>
<i class="far fa-file-code" aria-hidden="true" ng-if="file.type==='file' && isJsonFile(file.name)"></i>
<i class="far fa-file-image" aria-hidden="true" ng-if="file.type==='file' && isImageFile(file.name)"></i>
<i class="far fa-file-audio" aria-hidden="true" ng-if="file.type==='file' && isAudioFile(file.name)"></i>
{{file.name}}
</a>
</li>
</ul>
</div>
<div>
<span>
Download
<a href="https://github.com/InventivetalentDev/minecraft-assets/zipball/refs/heads/{{asset.version}}" title="Download .zip archive"><i class="fa fa-download" aria-hidden="true"></i> .zip</a>
<a href="https://github.com/InventivetalentDev/minecraft-assets/tarball/refs/heads/1.16.5{{asset.version}}" title="Download .tar.gz archive"><i class="fa fa-download" aria-hidden="true"></i> .tar.gz</a>
</span>
<span ng-show="assetIndex.length === 1000">
This list has been truncated. <a href="#" ng-click="loadMore()">Load more</a>
</span>
<span class="pull-right"><span class="text-muted">Files last downloaded & extracted on </span>{{versionInfo.downloadTimestamp | date: "medium"}}</span>
</div>
</div>
<div ng-show="asset.version && assetIndex.length <= 0">
<img src="/img/loading.svg">
<strong>Loading Assets...</strong>
</div>
<br/>
<br/>
<a href="https://www.patreon.com/bePatron?u=554075" data-patreon-widget-type="become-patron-button">Become a Patron!</a>
<script async src="https://c6.patreon.com/becomePatronButton.bundle.js"></script>
</div>
</div>
</div>
<footer class="footer navbar-fixed-bottom" style="background-color: #f5f5f5; padding-top: 16px; padding-bottom: 16px;">
<div class="container">
<div class="row">
<div class="col-sm-6">
<span>Maintained by <a href="https://inventivetalent.org/?utm_source=mcassets&utm_medium=author_link" target="_blank">inventivetalent</a></span>
Not affiliated with Minecraft / Mojang AB.
</div>
<div class="col-sm-6">
<span class="pull-right">
<span class="text-muted" title="{{githubRequestsReset>0 ? 'Resets on ' + (githubRequestsReset*1000 | date : 'medium') : ''}}">{{githubRequestsRemaining}} GitHub requests remaining</span>
<span ng-if="githubAccessToken" style="color: green;" title="GitHub authenticated! ({{githubUser.name}})"><i class="fa fa-check" aria-hidden="true"></i></span>
<span ng-if="githubAccessToken == undefined" style="color: red;" title="GitHub not yet authenticated"><i class="fa fa-times" aria-hidden="true"></i></span>
</span>
</div>
</div>
</div>
</footer>
<!-- MODALS -->
<div id="previewModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h1 class="modal-title">{{previewFile.name}}</h1>
</div>
<div class="modal-body">
<pre ng-if="previewFile._isText()">{{previewFile._content}}</pre>
<img class="img-responsive" ng-if="previewFile._isImage()" ng-src="{{previewFile.download_url}}" style="width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges;">
<audio ng-if="previewFile._isAudio()" controls>
<source ng-src="{{previewFile.download_url}}" type="{{previewFile._contentType}}">
</audio>
<div ng-if="previewFile._contentType && !previewFile._isText() && !previewFile._isImage() && !previewFile._isAudio()">
<p>
<strong>File cannot be displayed.</strong>
<br/>
Please use the links below to view/download the file directly.
</p>
</div>
<div ng-if="!previewFile._contentType">
<img src="/img/loading.svg">
</div>
</div>
<div class="modal-footer">
<span class="text-muted pull-left">
<a target="_blank" href="https://assets.mcasset.cloud/{{asset.version}}/{{previewFile.path}}">{{asset.version}}/{{previewFile.path}}</a>
</span>
<span>
<a href="{{previewFile.html_url}}" target="_blank"><i class="fa fa-github" aria-hidden="true"></i> View on GitHub</a>
<a href="{{previewFile.download_url}}" target="_blank"><i class="fa fa-download" aria-hidden="true"></i> Download File</a>
</span>
</div>
</div>
</div>
</div>
<div id="githubAuthModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h1 class="modal-title">GitHub authentication</h1>
</div>
<div class="modal-body">
<p>
<strong>Hey! Please authenticate via GitHub to use this website.</strong>
<br/>
<br/>
Non-authenticated requests to the GitHub API are limited to 60 per hour (see the bottom right corner),<br/>
please click the button below to authenticate yourself for up to 5,000 requests per hour.
<br/>
<br/>
<span class="text-muted">(This isn't required, but you'll run into problems when browsing a lot of files)</span>
<br/>
</p>
<div class="text-center">
<a href="https://auth.mcasset.cloud/github/index.php" class="btn btn-success">Authenticate via GitHub</a>
</div>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js" integrity="sha384-V6/dyDFv85/V/Ktq3ez5B80/c9ZY7jV9c/319rqwNOz3h9CIPdd2Eve0UQBYMMr/" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js" integrity="sha384-k+Qp/8rZxoiiYGVjOBiZwkEp5yv6clgl2EmwNaE1oUMlfmEYgCWazxf4CyxfZiWG" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular-cookies.min.js" integrity="sha384-4Rqc4WCYcTgQGo7N/eJANj8VFLYiS0J/XRW6ThAPed/9YJmlNO7iD+ZdbeKi1Eqx" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ng-meta/1.0.3/ngMeta.min.js"></script>
<script>
window.DOP_config = {
links: { // Replace with your links
paypal: "https://paypal.me/inventivetalent",
patreon: "https://patreon.com/inventivetalent"
},
enableAnalytics: true
}
</script>
<script src="https://cdn.jsdelivr.net/gh/InventivetalentDev/DonationPopup@master/DonationPopup.min.js"></script>
<script>
var isCrawler = /bot|googlebot|crawler|spider|robot|crawling/i.test(navigator.userAgent);
var assetApp = angular.module("assetApp", ["ngRoute", "ngCookies", "ngMeta"]);
assetApp.config(function ($locationProvider, ngMetaProvider) {
$locationProvider.html5Mode(true);
ngMetaProvider.useTitleSuffix(true);
ngMetaProvider.setDefaultTitleSuffix(" | Minecraft Assets");
ngMetaProvider.setDefaultTitle("MC Assets - Browser for Minecraft Asset Files");
ngMetaProvider.setDefaultTag("image", "https://mcasset.cloud/img/mc-assets-2-512.png");
});
assetApp.run(['ngMeta', function (ngMeta) {
ngMeta.init();
}]);
assetApp.controller("assetController", ["$scope", "$location", "$http", "$timeout", "$routeParams", "$cookies", "$window", "ngMeta", function ($scope, $location, $http, $timeout, $routeParams, $cookies, $window, ngMeta) {
ngMeta.setTitle("MC Assets - Browser for Minecraft Asset Files", "");
window._$scope = $scope;
$scope.asset = {
version: undefined,
path: "/",
pathElements: []
};
$scope.versionInfo = {
id: "",
type: "",
url: "",
time: "",
releaseTime: "",
downloadTimestamp: 0
};
$scope.assetsLoading = false;
$scope.assetIndex = [];
$scope.dirShas = {};
$scope.currentDir = "/";
$scope.parentDir = "/";
$scope.cachedResponses = {};
$scope.shouldLoadMore = false;
$scope.githubRequestsRemaining = 60;
$scope.githubRequestsReset = 0;
$scope.githubAccessToken = undefined;
$scope.githubUser = undefined;
$scope.versionChanged = function () {
$scope.asset.path = "/";
$scope.refreshPath();
$http({
url: "https://raw.githubusercontent.com/InventivetalentDev/minecraft-assets/" + $scope.getRef() + "/version.json"
}).then(function (response) {
$scope.versionInfo = response.data;
})
};
$scope.refreshPath = function (skipUrlUpdate) {
var split = $scope.asset.path.split("/");
$scope.asset.pathElements = [];
for (var i = 0; i < split.length; i++) {
if (split[i].length > 0) {// skip empty elements
$scope.asset.pathElements.push(split[i]);
}
}
let pathWithoutLast = $scope.asset.pathElements.slice(0, $scope.asset.pathElements.length);
if (pathWithoutLast.length > 0) {
pathWithoutLast.pop();
}
$scope.parentDir = pathWithoutLast.join("/");
var trimmedPath = $scope.asset.path;
if (trimmedPath.endsWith("/")) {
trimmedPath = trimmedPath.substring(0, trimmedPath.length - 1);
}
let dirChanged = false;
if (trimmedPath) {
if (trimmedPath !== $scope.currentDir) {
dirChanged = true;
}
$scope.currentDir = trimmedPath;
}
console.log("Current Dir: " + $scope.asset.path);
console.log("Parent Dir: " + $scope.parentDir);
if (dirChanged) {
$scope.shouldLoadMore = false;
}
if ($scope.shouldLoadMore) {
$scope.loadMore();
} else {
$scope.load();
}
if (!skipUrlUpdate) {
}
$location.path("/" + $scope.asset.version.replace(/__/g, "_").replace(/ /g, "_") + "/" + trimmedPath);
};
$scope.getRef = function () {
return $scope.asset.version.replace(/__/g, "_").replace(/ /g, "_");
}
$scope.load = function () {
$scope.assetIndex = [];
$scope.githubRequest("https://api.github.com/repos/InventivetalentDev/minecraft-assets/contents" + ($scope.currentDir || "") + "?ref=" + $scope.getRef(),
function (response) {
$scope.assetIndex = response.data;
$scope.updateShas();
},
function (error) {
});
};
$scope.loadMore = function () {
$scope.shouldLoadMore = true;
$scope.getCurrentDirSha(function (currentDirSha) {
console.log("Current Dir Sha: " + currentDirSha);
if (currentDirSha) {
$scope.assetIndex = [];
$scope.githubRequest("https://api.github.com/repos/InventivetalentDev/minecraft-assets/git/trees/" + currentDirSha,
function (response) {
let tempIndex = response.data.tree;
for (let asset of tempIndex) {
asset._type = asset.type;
if (asset.type === "tree") {
asset.type = "dir";
}
if (asset.type === "blob") {
asset.type = "file";
}
if (!asset.name) { // avoid using path as name again on cached responses
asset.name = asset.path;
asset._path = asset.path;
asset.path = $scope.currentDir + "/" + asset.path;
}
asset.url = "https://api.github.com/repos/InventivetalentDev/minecraft-assets/contents/" + asset.path + "?ref=" + $scope.getRef();
asset.html_url = "https://github.com/InventivetalentDev/minecraft-assets/tree/" + $scope.getRef() + "/" + asset.path;
asset.git_url = asset.url;
asset.download_url = "https://raw.githubusercontent.com/InventivetalentDev/minecraft-assets/" + $scope.getRef() + "/" + asset.path;
$scope.assetIndex.push(asset);
}
},
function (error) {
});
}
})
};
$scope.updateShas = function (source = $scope.assetIndex) {
for (let asset of source) {
if (asset.type === "dir") {
$scope.dirShas[asset.path] = asset.sha;
}
}
};
$scope.getCurrentDirSha = function (cb) {
if ($scope.dirShas.hasOwnProperty($scope.currentDir)) {
cb($scope.dirShas[$scope.currentDir]);
return;
}
$scope.githubRequest("https://api.github.com/repos/InventivetalentDev/minecraft-assets/contents" + $scope.parentDir + "?ref=" + $scope.asset.version.replace(/__/g, "_").replace(/ /g, "_"),
function (response) {
$scope.updateShas(response.data);
cb($scope.dirShas[$scope.currentDir]);
},
function (error) {
});
};
$scope.githubRequest = function (url, success, error) {
if ($scope.cachedResponses.hasOwnProperty(url)) {
success($scope.cachedResponses[url]);
return;
}
var headers = {};
if ($scope.githubAccessToken) {
headers["Authorization"] = "token " + atob($scope.githubAccessToken);
}
$http({
url: url,
headers: headers
}).then(function (response) {
console.log(response);
$scope.githubRequestsRemaining = parseInt(response.headers("X-RateLimit-Remaining"));
$scope.githubRequestsReset = parseInt(response.headers("X-RateLimit-Reset"));
$scope.cachedResponses[url] = response;
success(response);
}, function (response) {
console.log(response);
error(response);
if (response.status === 401) {
if (response.data.message === "Bad credentials") {// OAuth token is no longer valid
$cookies.remove("gh_access_token");
$scope.githubAccessToken = undefined;
if (!isCrawler)
$("#githubAuthModal").modal("show");
return;
}
}
if (response.status === 404) {
console.log(response.data.message)
if (response.data.message.startsWith("No commit found for the ref")) {
alert("Assets for this version are not yet generated.\n" +
"Please bug @Inventivtalent on twitter to get it updated ;)");
return;
}
}
alert("GitHub Error: " + response.data.message);
});
};
$scope.goToPath = function (path, $event) {
if ($event) {
$event.preventDefault();
}
$scope.asset.path = path;
$scope.refreshPath();
};
$scope.getJoinedPath = function (untilPos) {
var path = "";
for (var i = 0; i < Math.min(untilPos, $scope.asset.pathElements.length); i++) {
path += "/" + $scope.asset.pathElements[i];
}
return path;
};
$scope.openFile = function (file, $event) {
if ($event) {
$event.preventDefault();
}
console.log(file);
console.log(file.download_url);
// window.open(downloadUrl, "_blank");
ngMeta.setTitle(file.name);
$scope.previewFile = file;
$("#previewModal").modal("show");
$http({
url: file.download_url
}).then(function (response) {
$scope.previewFile._contentType = response.headers("Content-Type");
$scope.previewFile._isImage = function () {
return $scope.previewFile._contentType.startsWith('image/')
};
$scope.previewFile._isText = function () {
return $scope.previewFile._contentType.startsWith('text/')
};
$scope.previewFile._isAudio = function () {
return $scope.previewFile._contentType.startsWith('audio/')
};
$scope.previewFile._content = response.data;
// Try to format JSON
try {
if ($scope.previewFile._content.toString() === "[object Object]") {
console.info("File is JSON")
$scope.previewFile._content = JSON.stringify($scope.previewFile._content, null, 2);
}
} catch (e) {
}
});
$location.path("/" + $scope.asset.version.replace(/__/g, "_").replace(/ /g, "_") + "/" + file.path);
};
String.prototype.endsWith = function (suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
$scope.isJsonFile = function (name) {
return name.endsWith(".json");
};
$scope.isImageFile = function (name) {
return name.endsWith(".png");
};
$scope.isAudioFile = function (name) {
return name.endsWith(".ogg");
};
$scope.previewFile = undefined;
$scope.showOldVersions = false;
$scope.versions = {
latest: {
release: "",
snapshot: ""
},
versions: []
};
$scope.showNav = false;
$window.onscroll = function () {
$timeout(function () {
if (window.scrollY > 580) {
$scope.showNav = true;
} else {
$scope.showNav = false;
}
})
};
$timeout(function () {
// Load versions
$http({
url: "https://inventive-cors-anywhere.herokuapp.com/https://launchermeta.mojang.com/mc/game/version_manifest.json"
}).then(function (response) {
$scope.versions = response.data;
console.info("Latest Version: " + $scope.versions.latest.release + " (release) / " + $scope.versions.latest.snapshot + " (snapshot)")
});
// GitHub authentication
$scope.githubAccessToken = $cookies.get("gh_access_token");
if (!$scope.githubAccessToken) {
$scope.githubRequestsRemaining = 60;
if (!isCrawler)
$("#githubAuthModal").modal("show");
} else {
$scope.githubRequestsRemaining = 5000;
$scope.githubRequest("https://api.github.com/user?d=_",
function (response) {
$scope.githubUser = response.data;
console.log($scope.githubUser);
}, function (error) {
})
}
}, 250);
function handleHistoryChange() {
var path = $location.path();
console.log(path);
var pathSplit = path.split("\/").filter(function (value) {
return value.length > 0;
});
console.log(pathSplit);
if (pathSplit.length > 0) {
if (pathSplit[0].startsWith("index.html")) {
return;
}
$scope.asset.version = pathSplit[0].replace(/__/g, "_").replace(/ /g, "_");
console.log("URL version:" + pathSplit[0]);
if (pathSplit.length > 1) {
pathSplit.shift();
$scope.asset.path = pathSplit.join("/");
console.log("URL path:" + $scope.asset.path);
var trimmedPath = $scope.asset.path;
if (trimmedPath.endsWith("/")) {
trimmedPath = trimmedPath.substring(0, trimmedPath.length - 1);
}
$scope.githubRequest("https://api.github.com/repos/InventivetalentDev/minecraft-assets/contents" + trimmedPath + "?ref=" + $scope.asset.version.replace(/__/g, "_").replace(/ /g, "_"),
function (response) {
console.log(response);
if (!Array.isArray(response.data)) {
// Probably a file
$scope.openFile(response.data);
pathSplit.pop();
$scope.asset.path = pathSplit.join("/");
}
$scope.refreshPath(true);
},
function (error) {
});
} else {
$scope.asset.path = "/";
$scope.refreshPath(true);
}
}
}
$timeout(handleHistoryChange, 1000);
$scope.$on('$locationChangeSuccess', function (event, newUrl, oldUrl) {
console.log("$locationChangeSuccess");
console.log(oldUrl, "->", newUrl)
if (newUrl !== oldUrl) {
handleHistoryChange();
}
});
}]);
</script>
</body>
</html>