1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-30 10:36:35 +02:00

Server: Allow giving a different version number to forks

This commit is contained in:
Laurent Cozic 2023-05-17 18:16:29 +01:00
parent a04be2b28a
commit 091eff9bc2
6 changed files with 23 additions and 10 deletions

View File

@ -4,7 +4,7 @@ require('source-map-support').install();
import * as Koa from 'koa';
import * as fs from 'fs-extra';
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 { AppContext, Env, KoaNext } from './utils/types';
import FsDriverNode from '@joplin/lib/fs-driver-node';
@ -252,7 +252,7 @@ async function main() {
} else {
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) {
appLogger().info(`Checking for time drift using NTP server: ${config().NTP_SERVER}`);

View File

@ -7,6 +7,9 @@ import parseStorageDriverConnectionString from './models/items/storage/parseStor
interface PackageJson {
version: string;
joplinServer: {
forkVersion: string;
};
}
const packageJson: PackageJson = require(`${__dirname}/packageInfo.js`);
@ -32,6 +35,13 @@ function databaseHostFromEnv(runningInDocker: boolean, env: EnvVariables): strin
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 {
const baseConfig: DatabaseConfig = {
client: DatabaseConfigClient.Null,
@ -114,10 +124,12 @@ export async function initConfig(envType: Env, env: EnvVariables, overrides: any
const baseUrl = baseUrlFromEnv(env, appPort);
const apiBaseUrl = env.API_BASE_URL ? env.API_BASE_URL : baseUrl;
const supportEmail = env.SUPPORT_EMAIL;
const forkVersion = packageJson.joplinServer?.forkVersion;
config_ = {
...env,
appVersion: packageJson.version,
appVersion: forkVersion ? forkVersion : packageJson.version,
joplinServerVersion: packageJson.version,
appName,
isJoplinCloud: apiBaseUrl.includes('.joplincloud.com') || apiBaseUrl.includes('.joplincloud.local'),
env: envType,

View File

@ -7,20 +7,20 @@ const compareVersions = require('compare-versions');
export default async function(ctx: AppContext, next: KoaNext): Promise<void> {
if (!isApiRequest(ctx)) return next();
const appVersion = config().appVersion;
const joplinServerVersion = config().joplinServerVersion;
const minVersion = ctx.headers['x-api-min-version'];
// For now we don't require this header to be set to keep compatibility with
// older clients.
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
// 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.
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();

View File

@ -1,7 +1,7 @@
import * as Mustache from 'mustache';
import * as fs from 'fs-extra';
import { extname } from 'path';
import config from '../config';
import config, { fullVersionString } from '../config';
import { filename } from '@joplin/lib/path-utils';
import { NotificationView } from '../utils/types';
import { User } from '../services/database/types';
@ -40,7 +40,7 @@ interface GlobalParams {
notifications?: NotificationView[];
hasNotifications?: boolean;
owner?: User;
appVersion?: string;
fullVersionString?: string;
appName?: string;
termsUrl?: string;
privacyUrl?: string;
@ -171,7 +171,7 @@ export default class MustacheService {
baseUrl: config().baseUrl,
joplinAppBaseUrl: config().joplinAppBaseUrl,
prefersDarkEnabled: this.prefersDarkEnabled_,
appVersion: config().appVersion,
fullVersionString: fullVersionString(config()),
appName: config().appName,
termsUrl: config().termsEnabled ? makeUrl(UrlType.Terms) : '',
privacyUrl: config().termsEnabled ? makeUrl(UrlType.Privacy) : '',

View File

@ -133,6 +133,7 @@ export interface StorageDriverConfig {
export interface Config extends EnvVariables {
appVersion: string;
joplinServerVersion: string; // May be different from appVersion, if this is a fork of JS
appName: string;
env: Env;
port: number;

View File

@ -1,5 +1,5 @@
<div class="footer">
<div class="content has-text-centered">
{{global.appName}} {{global.appVersion}}, copyright &copy; 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 &copy; 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>