fix: scope tokens per host, harden Gitea support, port upstream fixes
Fork fixes: - Global token is GitHub-only; never sent to Gitea/Forgejo hosts - Gitea: download assets via browser_download_url (+token) so private repos work - Gitea URL parsing keeps port and sub-path installs, strips browser sub-pages - GitHub detected by hostname, not substring - Gitea releases: follow pagination (X-Total-Count), skip drafts - Gitea token validation against the repo; 404 is no longer "valid" - Settings tab and migration log use this plugin's own id/folder - Check-only mode no longer reinstalls/enables a missing plugin folder - reloadPlugin reports load failures (enablePlugin resolves false) - Repository / release-notes links work for both providers Ported from upstream BRAT 2.2.0: - Release sort: semver tags first, date fallback - Null-safe version comparison, JSON shape guards - Drop obsidian-daily-notes-interface (read daily note format directly) - Notice.messageEl, CSS without !important, console.debug/error
This commit is contained in:
1 parent
91247d31e2
commit
d3f3fe926a
21 files changed
+548
-495
No files matched your search
+44
-8
@@ -1,8 +1,43 @@
|
||||
import type { TFile } from "obsidian";
|
||||
import { moment, Platform } from "obsidian";
|
||||
import { getDailyNoteSettings } from "obsidian-daily-notes-interface";
|
||||
import { moment, Platform, TFile } from "obsidian";
|
||||
import type BratPlugin from "../main";
|
||||
|
||||
const DEFAULT_DAILY_NOTE_FORMAT = "YYYY-MM-DD";
|
||||
|
||||
interface DailyNotesPluginLike {
|
||||
instance?: {
|
||||
options?: {
|
||||
format?: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
interface PeriodicNotesPluginLike {
|
||||
settings?: {
|
||||
daily?: {
|
||||
enabled?: boolean;
|
||||
format?: string;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/** Daily note date format, from Periodic Notes if it handles dailies, else core Daily notes. */
|
||||
function getDailyNoteFormat(plugin: BratPlugin): string {
|
||||
// @ts-expect-error app.plugins is not part of the public API
|
||||
const periodicNotes = plugin.app.plugins.getPlugin(
|
||||
"periodic-notes",
|
||||
) as PeriodicNotesPluginLike | null;
|
||||
const periodicDailySettings = periodicNotes?.settings?.daily;
|
||||
if (periodicDailySettings?.enabled) {
|
||||
return periodicDailySettings.format || DEFAULT_DAILY_NOTE_FORMAT;
|
||||
}
|
||||
|
||||
// @ts-expect-error app.internalPlugins is not part of the public API
|
||||
const dailyNotes = plugin.app.internalPlugins.getPluginById(
|
||||
"daily-notes",
|
||||
) as DailyNotesPluginLike | null;
|
||||
return dailyNotes?.instance?.options?.format || DEFAULT_DAILY_NOTE_FORMAT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs events to a log file
|
||||
*
|
||||
@@ -16,21 +51,22 @@ export async function logger(
|
||||
textToLog: string,
|
||||
verboseLoggingOn = false,
|
||||
): Promise<void> {
|
||||
if (plugin.settings.debuggingMode) console.log(`BRAT: ${textToLog}`);
|
||||
if (plugin.settings.debuggingMode) console.debug(`BRAT: ${textToLog}`);
|
||||
if (plugin.settings.loggingEnabled) {
|
||||
if (!plugin.settings.loggingVerboseEnabled && verboseLoggingOn) return;
|
||||
|
||||
const fileName = `${plugin.settings.loggingPath}.md`;
|
||||
const dateOutput = `[[${moment().format(getDailyNoteSettings().format).toString()}]] ${moment().format("HH:mm")}`;
|
||||
const now = moment();
|
||||
const dateOutput = `[[${now.format(getDailyNoteFormat(plugin))}]] ${now.format("HH:mm")}`;
|
||||
const os = Platform.isDesktop
|
||||
? (window.require("os") as { hostname: () => string })
|
||||
: null;
|
||||
const machineName = Platform.isDesktop ? os?.hostname() : "MOBILE";
|
||||
const output = `${dateOutput} ${machineName} ${textToLog.replace("\n", " ")}\n`;
|
||||
|
||||
let file = plugin.app.vault.getAbstractFileByPath(fileName) as TFile;
|
||||
if (!file) {
|
||||
file = await plugin.app.vault.create(fileName, output);
|
||||
const file = plugin.app.vault.getAbstractFileByPath(fileName);
|
||||
if (!(file instanceof TFile)) {
|
||||
await plugin.app.vault.create(fileName, output);
|
||||
} else {
|
||||
await plugin.app.vault.append(file, output);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user