Automatic GistId recognition

This commit is contained in:
suziwen 2024-08-05 22:12:35 +08:00
parent 9bb9319e33
commit 87f76aa795
3 changed files with 16 additions and 2 deletions

View File

@ -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) ->

View File

@ -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())

View File

@ -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