mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-02 12:47:41 +02:00
Server: Allow giving a different version number to forks
This commit is contained in:
parent
a04be2b28a
commit
091eff9bc2
@ -4,7 +4,7 @@ require('source-map-support').install();
|
|||||||
import * as Koa from 'koa';
|
import * as Koa from 'koa';
|
||||||
import * as fs from 'fs-extra';
|
import * as fs from 'fs-extra';
|
||||||
import Logger, { LoggerWrapper, TargetType } from '@joplin/lib/Logger';
|
import Logger, { LoggerWrapper, TargetType } from '@joplin/lib/Logger';
|
||||||
import config, { initConfig, runningInDocker } from './config';
|
import config, { fullVersionString, initConfig, runningInDocker } from './config';
|
||||||
import { migrateLatest, waitForConnection, sqliteDefaultDir, latestMigration } from './db';
|
import { migrateLatest, waitForConnection, sqliteDefaultDir, latestMigration } from './db';
|
||||||
import { AppContext, Env, KoaNext } from './utils/types';
|
import { AppContext, Env, KoaNext } from './utils/types';
|
||||||
import FsDriverNode from '@joplin/lib/fs-driver-node';
|
import FsDriverNode from '@joplin/lib/fs-driver-node';
|
||||||
@ -252,7 +252,7 @@ async function main() {
|
|||||||
} else {
|
} else {
|
||||||
runCommandAndExitApp = false;
|
runCommandAndExitApp = false;
|
||||||
|
|
||||||
appLogger().info(`Starting server v${config().appVersion} (${env}) on port ${config().port} and PID ${process.pid}...`);
|
appLogger().info(`Starting server ${fullVersionString(config())} (${env}) on port ${config().port} and PID ${process.pid}...`);
|
||||||
|
|
||||||
if (config().maxTimeDrift) {
|
if (config().maxTimeDrift) {
|
||||||
appLogger().info(`Checking for time drift using NTP server: ${config().NTP_SERVER}`);
|
appLogger().info(`Checking for time drift using NTP server: ${config().NTP_SERVER}`);
|
||||||
|
@ -7,6 +7,9 @@ import parseStorageDriverConnectionString from './models/items/storage/parseStor
|
|||||||
|
|
||||||
interface PackageJson {
|
interface PackageJson {
|
||||||
version: string;
|
version: string;
|
||||||
|
joplinServer: {
|
||||||
|
forkVersion: string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const packageJson: PackageJson = require(`${__dirname}/packageInfo.js`);
|
const packageJson: PackageJson = require(`${__dirname}/packageInfo.js`);
|
||||||
@ -32,6 +35,13 @@ function databaseHostFromEnv(runningInDocker: boolean, env: EnvVariables): strin
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const fullVersionString = (config: Config) => {
|
||||||
|
const output: string[] = [];
|
||||||
|
output.push(`v${config.appVersion}`);
|
||||||
|
if (config.appVersion !== config.joplinServerVersion) output.push(`(Based on Joplin Server v${config.joplinServerVersion})`);
|
||||||
|
return output.join(' ');
|
||||||
|
};
|
||||||
|
|
||||||
function databaseConfigFromEnv(runningInDocker: boolean, env: EnvVariables): DatabaseConfig {
|
function databaseConfigFromEnv(runningInDocker: boolean, env: EnvVariables): DatabaseConfig {
|
||||||
const baseConfig: DatabaseConfig = {
|
const baseConfig: DatabaseConfig = {
|
||||||
client: DatabaseConfigClient.Null,
|
client: DatabaseConfigClient.Null,
|
||||||
@ -114,10 +124,12 @@ export async function initConfig(envType: Env, env: EnvVariables, overrides: any
|
|||||||
const baseUrl = baseUrlFromEnv(env, appPort);
|
const baseUrl = baseUrlFromEnv(env, appPort);
|
||||||
const apiBaseUrl = env.API_BASE_URL ? env.API_BASE_URL : baseUrl;
|
const apiBaseUrl = env.API_BASE_URL ? env.API_BASE_URL : baseUrl;
|
||||||
const supportEmail = env.SUPPORT_EMAIL;
|
const supportEmail = env.SUPPORT_EMAIL;
|
||||||
|
const forkVersion = packageJson.joplinServer?.forkVersion;
|
||||||
|
|
||||||
config_ = {
|
config_ = {
|
||||||
...env,
|
...env,
|
||||||
appVersion: packageJson.version,
|
appVersion: forkVersion ? forkVersion : packageJson.version,
|
||||||
|
joplinServerVersion: packageJson.version,
|
||||||
appName,
|
appName,
|
||||||
isJoplinCloud: apiBaseUrl.includes('.joplincloud.com') || apiBaseUrl.includes('.joplincloud.local'),
|
isJoplinCloud: apiBaseUrl.includes('.joplincloud.com') || apiBaseUrl.includes('.joplincloud.local'),
|
||||||
env: envType,
|
env: envType,
|
||||||
|
@ -7,20 +7,20 @@ const compareVersions = require('compare-versions');
|
|||||||
export default async function(ctx: AppContext, next: KoaNext): Promise<void> {
|
export default async function(ctx: AppContext, next: KoaNext): Promise<void> {
|
||||||
if (!isApiRequest(ctx)) return next();
|
if (!isApiRequest(ctx)) return next();
|
||||||
|
|
||||||
const appVersion = config().appVersion;
|
const joplinServerVersion = config().joplinServerVersion;
|
||||||
const minVersion = ctx.headers['x-api-min-version'];
|
const minVersion = ctx.headers['x-api-min-version'];
|
||||||
|
|
||||||
// For now we don't require this header to be set to keep compatibility with
|
// For now we don't require this header to be set to keep compatibility with
|
||||||
// older clients.
|
// older clients.
|
||||||
if (!minVersion) return next();
|
if (!minVersion) return next();
|
||||||
|
|
||||||
const diff = compareVersions(appVersion, minVersion);
|
const diff = compareVersions(joplinServerVersion, minVersion);
|
||||||
|
|
||||||
// We only throw an error if the client requires a version of Joplin Server
|
// We only throw an error if the client requires a version of Joplin Server
|
||||||
// that's ahead of what's installed. This is mostly to automatically notify
|
// that's ahead of what's installed. This is mostly to automatically notify
|
||||||
// those who self-host so that they know they need to upgrade Joplin Server.
|
// those who self-host so that they know they need to upgrade Joplin Server.
|
||||||
if (diff < 0) {
|
if (diff < 0) {
|
||||||
throw new ErrorPreconditionFailed(`Joplin Server v${minVersion} is required but v${appVersion} is installed. Please upgrade Joplin Server.`);
|
throw new ErrorPreconditionFailed(`Joplin Server v${minVersion} is required but v${joplinServerVersion} is installed. Please upgrade Joplin Server.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import * as Mustache from 'mustache';
|
import * as Mustache from 'mustache';
|
||||||
import * as fs from 'fs-extra';
|
import * as fs from 'fs-extra';
|
||||||
import { extname } from 'path';
|
import { extname } from 'path';
|
||||||
import config from '../config';
|
import config, { fullVersionString } from '../config';
|
||||||
import { filename } from '@joplin/lib/path-utils';
|
import { filename } from '@joplin/lib/path-utils';
|
||||||
import { NotificationView } from '../utils/types';
|
import { NotificationView } from '../utils/types';
|
||||||
import { User } from '../services/database/types';
|
import { User } from '../services/database/types';
|
||||||
@ -40,7 +40,7 @@ interface GlobalParams {
|
|||||||
notifications?: NotificationView[];
|
notifications?: NotificationView[];
|
||||||
hasNotifications?: boolean;
|
hasNotifications?: boolean;
|
||||||
owner?: User;
|
owner?: User;
|
||||||
appVersion?: string;
|
fullVersionString?: string;
|
||||||
appName?: string;
|
appName?: string;
|
||||||
termsUrl?: string;
|
termsUrl?: string;
|
||||||
privacyUrl?: string;
|
privacyUrl?: string;
|
||||||
@ -171,7 +171,7 @@ export default class MustacheService {
|
|||||||
baseUrl: config().baseUrl,
|
baseUrl: config().baseUrl,
|
||||||
joplinAppBaseUrl: config().joplinAppBaseUrl,
|
joplinAppBaseUrl: config().joplinAppBaseUrl,
|
||||||
prefersDarkEnabled: this.prefersDarkEnabled_,
|
prefersDarkEnabled: this.prefersDarkEnabled_,
|
||||||
appVersion: config().appVersion,
|
fullVersionString: fullVersionString(config()),
|
||||||
appName: config().appName,
|
appName: config().appName,
|
||||||
termsUrl: config().termsEnabled ? makeUrl(UrlType.Terms) : '',
|
termsUrl: config().termsEnabled ? makeUrl(UrlType.Terms) : '',
|
||||||
privacyUrl: config().termsEnabled ? makeUrl(UrlType.Privacy) : '',
|
privacyUrl: config().termsEnabled ? makeUrl(UrlType.Privacy) : '',
|
||||||
|
@ -133,6 +133,7 @@ export interface StorageDriverConfig {
|
|||||||
|
|
||||||
export interface Config extends EnvVariables {
|
export interface Config extends EnvVariables {
|
||||||
appVersion: string;
|
appVersion: string;
|
||||||
|
joplinServerVersion: string; // May be different from appVersion, if this is a fork of JS
|
||||||
appName: string;
|
appName: string;
|
||||||
env: Env;
|
env: Env;
|
||||||
port: number;
|
port: number;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<div class="footer">
|
<div class="footer">
|
||||||
<div class="content has-text-centered">
|
<div class="content has-text-centered">
|
||||||
{{global.appName}} {{global.appVersion}}, copyright © 2022 JOPLIN.{{#global.termsUrl}} For more information, see the <a href="{{global.termsUrl}}">Terms of Use</a> and <a href="{{global.privacyUrl}}">Privacy Policy</a>{{/global.termsUrl}}
|
{{global.appName}} {{global.fullVersionString}}, copyright © 2022 JOPLIN.{{#global.termsUrl}} For more information, see the <a href="{{global.termsUrl}}">Terms of Use</a> and <a href="{{global.privacyUrl}}">Privacy Policy</a>{{/global.termsUrl}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
Loading…
Reference in New Issue
Block a user