diff --git a/app/boot.php b/app/boot.php
index 92231d8..9ac1d2d 100644
--- a/app/boot.php
+++ b/app/boot.php
@@ -28,7 +28,7 @@
$profile = json_decode(file_get_contents($PROFILE_PATH), true);
if (!is_file($MODELS_PATH)) {
- importModels($profile['uid'], $MODELS_PATH);
+ importModels($profile['username'], $MODELS_PATH);
}
$models = json_decode(file_get_contents($MODELS_PATH), true);
diff --git a/app/js/main.js b/app/js/main.js
index 993e98f..c7bff22 100644
--- a/app/js/main.js
+++ b/app/js/main.js
@@ -26,11 +26,19 @@ $(document).ready(function(){
}
}
- $('button[data-action]').on('click', function(){
+ $('button[data-action="forceUpdate"]').on('click', function(){
var $this = $(this);
var attribute = $this.attr('data-action').replace('sort', 'data');
$('button[data-action]').removeClass('active');
$this.addClass('active');
tinysort('ul.skfb-grid>li', { sortFunction: getSortFunction(attribute)});
});
+
+ // Check for update
+ $.get('https://api.github.com/repos/mauricesvay/sketchfab-portfolio/releases/latest').then(function(response){
+ var currentVersion = $('#current-version').text();
+ if (response.name !== currentVersion) {
+ $('#current-version').html('New version available: ' + response.name + '');
+ }
+ });
});
diff --git a/app/lib/api/models.php b/app/lib/api/models.php
index 14a0745..5e6e51c 100644
--- a/app/lib/api/models.php
+++ b/app/lib/api/models.php
@@ -3,11 +3,12 @@
/**
* Fetch paginated models for given user id
*/
-function fetchModels($userId, $offset=0) {
- $baseUrl = 'https://api.sketchfab.com/v2/models';
+function fetchModels($username, $cursor='') {
+ $baseUrl = 'https://api.sketchfab.com/v3/models';
$params = array(
- 'user' => $userId,
- 'offset' => $offset
+ 'user' => $username,
+ 'sort_by' => '-createdAt',
+ 'cursor' => $cursor
);
$url = $baseUrl . '?' . http_build_query($params);
return fetchJson($url);
@@ -16,14 +17,26 @@ function fetchModels($userId, $offset=0) {
/**
* Fetch all models for given user id
*/
-function fetchAllModels($userId) {
- $offset = 0;
+function fetchAllModels($username) {
+ $cursor = '';
$models = array();
do {
- $response = fetchModels($userId, $offset);
+ $response = fetchModels($username, $cursor);
+ $params = array();
+
+ // Extract cursor
+ if ($response['next'] !== null) {
+ $parsed = parse_url($response['next'], PHP_URL_QUERY);
+ if($parsed !== null) {
+ parse_str($parsed, $params);
+ if (array_key_exists ('cursor', $params)) {
+ $cursor = $params['cursor'];
+ }
+ }
+ }
+
$models = array_merge($models, $response['results']);
- $offset = $offset + $response['count'];
} while ($response['next']);
return $models;
@@ -32,8 +45,8 @@ function fetchAllModels($userId) {
/**
* Save all user models to file
*/
-function importModels($uid, $filePath) {
- $models = fetchAllModels($uid);
+function importModels($username, $filePath) {
+ $models = fetchAllModels($username);
makeDirForPath($filePath);
return file_put_contents($filePath, json_encode($models));
}
diff --git a/app/templates/footer.html b/app/templates/footer.html
index f7c0dcc..7b497fb 100644
--- a/app/templates/footer.html
+++ b/app/templates/footer.html
@@ -3,7 +3,9 @@
-
{{ "now"|date('Y', timezone="UTC") }}
- powered by Sketchfab Portfolio
+ powered by
+ Sketchfab Portfolio
+ (1.1.0)
and Sketchfab
diff --git a/app/templates/index.html b/app/templates/index.html
index a128522..f186203 100644
--- a/app/templates/index.html
+++ b/app/templates/index.html
@@ -20,7 +20,7 @@