From 87f76aa795a7a26e9b6aba169d82d049c28ccd58 Mon Sep 17 00:00:00 2001 From: suziwen Date: Mon, 5 Aug 2024 22:12:35 +0800 Subject: [PATCH] Automatic GistId recognition --- .../src/module/sync_storage.coffee | 7 ++++++- omega-web/src/omega/controllers/io.coffee | 9 +++++++++ omega-web/src/partials/io.jade | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/omega-target-chromium-extension/src/module/sync_storage.coffee b/omega-target-chromium-extension/src/module/sync_storage.coffee index a647ac2..02bfa7e 100644 --- a/omega-target-chromium-extension/src/module/sync_storage.coffee +++ b/omega-target-chromium-extension/src/module/sync_storage.coffee @@ -288,7 +288,12 @@ class ChromeSyncStorage extends OmegaTarget.Storage # param(withRemoteData) retrive gist file content ## init: (args) -> - gistId = args.gistId + gistId = args.gistId || '' + if gistId.indexOf('/') >= 0 + # get gistId from url `https://gist.github.com/{username}/{gistId}` + gistId = gistId.replace(/\/+$/, '') + gistId = gistId.split('/') + gistId = gistId[gistId.length - 1] gistToken = args.gistToken return new Promise((resolve, reject) -> getLastCommit(gistId).then( (lastGistCommit) -> diff --git a/omega-web/src/omega/controllers/io.coffee b/omega-web/src/omega/controllers/io.coffee index 8a3843a..a7544fe 100644 --- a/omega-web/src/omega/controllers/io.coffee +++ b/omega-web/src/omega/controllers/io.coffee @@ -2,6 +2,14 @@ angular.module('omega').controller 'IoCtrl', ( $scope, $rootScope, $window, $http, omegaTarget, downloadFile ) -> + getGistId = (gistUrl = '') -> + # get gistId from url `https://gist.github.com/{username}/{gistId}` + # or directly gistId + gistId = gistUrl.replace(/\/+$/, '') + gistId = gistId.split('/') + gistId = gistId[gistId.length - 1] + return gistId + omegaTarget.state([ 'web.restoreOnlineUrl', 'gistId', @@ -13,6 +21,7 @@ angular.module('omega').controller 'IoCtrl', ( $scope.restoreOnlineUrl = url if gistId $scope.gistId = gistId + $scope.gistUrl = "https://gist.github.com/" + getGistId(gistId) if gistToken $scope.gistToken = gistToken $scope.lastGistSync = new Date(lastGistSync or Date.now()) diff --git a/omega-web/src/partials/io.jade b/omega-web/src/partials/io.jade index 28f3d69..bee45da 100644 --- a/omega-web/src/partials/io.jade +++ b/omega-web/src/partials/io.jade @@ -74,7 +74,7 @@ section.settings-group | {{'('}} | {{lastGistState}} | {{')'}} - a(href="https://gist.github.com/{{gistId}}" role="button" target="_blank") + a(href="{{gistUrl}}" role="button" target="_blank") | {{' '}} span.glyphicon.glyphicon-link br