From e6f1f3add42065a0ad8fa6bae733188809af6034 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 24 Feb 2019 23:48:28 -0500 Subject: [PATCH] feat: git changes processing --- CHANGELOG.md | 13 ++ client/components/admin/admin-storage.vue | 12 +- .../admin/storage/storage-query-status.gql | 1 + server/db/migrations-sqlite/2.0.0-beta.11.js | 3 +- server/graph/resolvers/storage.js | 6 +- server/graph/schemas/storage.graphql | 3 +- server/jobs/sync-storage.js | 15 ++ server/models/editors.js | 10 ++ server/models/pageHistory.js | 4 +- server/models/pages.js | 92 +++++++++++-- server/models/storage.js | 9 +- server/modules/storage/git/definition.yml | 4 + server/modules/storage/git/storage.js | 128 ++++++++++++++++++ 13 files changed, 275 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b645870..42f2ce09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,19 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [2.0.0-beta.XX] - 2018-XX-XX +### Added +- Added Git changes processing (add/modify/delete) +- Added Storage last sync date in status panel +- Added Dev Flags +- Added HTTP to HTTPS redirect server option + +### Fixed +- Fixed SQLite migrations + +### Changed +- Split admin dev section into separate pages + ## [2.0.0-beta.42] - 2018-02-17 ### Added - Added Patreon link in Contribute admin page diff --git a/client/components/admin/admin-storage.vue b/client/components/admin/admin-storage.vue index 55409338..ddc7d939 100644 --- a/client/components/admin/admin-storage.vue +++ b/client/components/admin/admin-storage.vue @@ -54,10 +54,18 @@ :color='getStatusColor(tgt.status)' dark flat - :extended='tgt.status === `error`', - extension-height='100' + :extended='tgt.status !== `pending`', + :extension-height='tgt.status === `error` ? 100 : 70' ) .pa-3.red.darken-2.radius-7(v-if='tgt.status === `error`', slot='extension') {{tgt.message}} + v-toolbar.radius-7( + color='green darken-2' + v-else-if='tgt.status !== `pending`' + slot='extension' + flat + dense + ) + span Last synchronization {{tgt.lastAttempt | moment('from') }} .body-2 {{tgt.title}} v-spacer .body-1 {{tgt.status}} diff --git a/client/graph/admin/storage/storage-query-status.gql b/client/graph/admin/storage/storage-query-status.gql index a5a81497..9a9e1f44 100644 --- a/client/graph/admin/storage/storage-query-status.gql +++ b/client/graph/admin/storage/storage-query-status.gql @@ -5,6 +5,7 @@ query { title status message + lastAttempt } } } diff --git a/server/db/migrations-sqlite/2.0.0-beta.11.js b/server/db/migrations-sqlite/2.0.0-beta.11.js index 998730fa..ef4580ac 100644 --- a/server/db/migrations-sqlite/2.0.0-beta.11.js +++ b/server/db/migrations-sqlite/2.0.0-beta.11.js @@ -16,11 +16,12 @@ exports.up = knex => { table.string('createdAt').notNullable() table.string('action').defaultTo('updated') + table.integer('pageId').unsigned() table.string('editorKey').references('key').inTable('editors') table.string('localeCode', 2).references('code').inTable('locales') table.integer('authorId').unsigned().references('id').inTable('users') }) - .raw(`INSERT INTO pageHistory SELECT id,path,hash,title,description,isPrivate,isPublished,publishStartDate,publishEndDate,content,contentType,createdAt,'updated' AS action,editorKey,localeCode,authorId FROM pageHistory_old;`) + .raw(`INSERT INTO pageHistory SELECT id,path,hash,title,description,isPrivate,isPublished,publishStartDate,publishEndDate,content,contentType,createdAt,'updated' AS action,pageId,editorKey,localeCode,authorId FROM pageHistory_old;`) .dropTable('pageHistory_old') } diff --git a/server/graph/resolvers/storage.js b/server/graph/resolvers/storage.js index 4899af5a..632c8398 100644 --- a/server/graph/resolvers/storage.js +++ b/server/graph/resolvers/storage.js @@ -45,7 +45,8 @@ module.exports = { key: tgt.key, title: targetInfo.title, status: _.get(tgt, 'state.status', 'pending'), - message: _.get(tgt, 'state.message', 'Initializing...') + message: _.get(tgt, 'state.message', 'Initializing...'), + lastAttempt: _.get(tgt, 'state.lastAttempt', null) } }) } @@ -64,7 +65,8 @@ module.exports = { }, {}), state: { status: 'pending', - message: 'Initializing...' + message: 'Initializing...', + lastAttempt: null } }).where('key', tgt.key) } diff --git a/server/graph/schemas/storage.graphql b/server/graph/schemas/storage.graphql index 783929f1..b82b1b1e 100644 --- a/server/graph/schemas/storage.graphql +++ b/server/graph/schemas/storage.graphql @@ -65,5 +65,6 @@ type StorageStatus { key: String! title: String! status: String! - message: String + message: String! + lastAttempt: String! } diff --git a/server/jobs/sync-storage.js b/server/jobs/sync-storage.js index dc0bb8d6..9208f2c4 100644 --- a/server/jobs/sync-storage.js +++ b/server/jobs/sync-storage.js @@ -10,11 +10,26 @@ module.exports = async (targetKey) => { if (target) { await target.fn.sync() WIKI.logger.info(`Syncing with storage target ${targetKey}: [ COMPLETED ]`) + + await WIKI.models.storage.query().patch({ + state: { + status: 'operational', + message: '', + lastAttempt: new Date().toISOString() + } + }).where('key', targetKey) } else { throw new Error('Invalid storage target. Unable to perform sync.') } } catch (err) { WIKI.logger.error(`Syncing with storage target ${targetKey}: [ FAILED ]`) WIKI.logger.error(err.message) + await WIKI.models.storage.query().patch({ + state: { + status: 'error', + message: err.message, + lastAttempt: new Date().toISOString() + } + }).where('key', targetKey) } } diff --git a/server/models/editors.js b/server/models/editors.js index 29e3db6c..f7ee494d 100644 --- a/server/models/editors.js +++ b/server/models/editors.js @@ -90,4 +90,14 @@ module.exports = class Editor extends Model { WIKI.logger.error(err) } } + + static async getDefaultEditor(contentType) { + // TODO - hardcoded for now + switch (contentType) { + case 'markdown': + return 'markdown' + default: + return 'code' + } + } } diff --git a/server/models/pageHistory.js b/server/models/pageHistory.js index be7370a8..145e9eeb 100644 --- a/server/models/pageHistory.js +++ b/server/models/pageHistory.js @@ -93,8 +93,8 @@ module.exports = class PageHistory extends Model { description: opts.description, editorKey: opts.editorKey, hash: opts.hash, - isPrivate: opts.isPrivate, - isPublished: opts.isPublished, + isPrivate: (opts.isPrivate === true || opts.isPrivate === 1), + isPublished: (opts.isPublished === true || opts.isPublished === 1), localeCode: opts.localeCode, path: opts.path, publishEndDate: opts.publishEndDate || '', diff --git a/server/models/pages.js b/server/models/pages.js index 7e922999..c3ff8acf 100644 --- a/server/models/pages.js +++ b/server/models/pages.js @@ -4,9 +4,16 @@ const JSBinType = require('js-binary').Type const pageHelper = require('../helpers/page') const path = require('path') const fs = require('fs-extra') +const yaml = require('js-yaml') /* global WIKI */ +const frontmatterRegex = { + html: /^()?(?:\n|\r)*([\w\W]*)*/, + legacy: /^(