Skip to content

Commit 06fbd55

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents f073c9d + 07d880e commit 06fbd55

3 files changed

Lines changed: 20 additions & 26 deletions

File tree

main.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80524,17 +80524,12 @@ var AbstractWordPressClient = class {
8052480524
const images = getImages(postParams.content);
8052580525
for (const img of images) {
8052680526
if (!img.srcIsUrl) {
80527-
const splitFile = img.src.split(".");
80528-
const ext = splitFile.pop();
80529-
const fileName = splitFile.join(".");
80530-
let filePath = await this.plugin.app.vault.getAvailablePathForAttachments(
80531-
fileName,
80532-
ext,
80533-
activeFile
80534-
);
80535-
const pathRegex = /(.*) \d+\.(.*)/;
80536-
filePath = filePath.replace(pathRegex, "$1.$2");
80537-
const imgFile = this.plugin.app.vault.getAbstractFileByPath(filePath);
80527+
img.src = decodeURI(img.src);
80528+
const fileName = img.src.split("/").pop();
80529+
if (fileName === void 0)
80530+
continue;
80531+
let normPath = this.plugin.app.metadataCache.getFirstLinkpathDest(img.src, fileName);
80532+
const imgFile = normPath;
8053880533
if (imgFile instanceof import_obsidian8.TFile) {
8053980534
const content = await this.plugin.app.vault.readBinary(imgFile);
8054080535
const fileType = import_file_type_checker.default.detectFile(content);
@@ -81083,7 +81078,7 @@ var WpRestClient = class extends AbstractWordPressClient {
8108381078
async getCategories(certificate) {
8108481079
var _a;
8108581080
const data = await this.client.httpGet(
81086-
getUrl((_a = this.context.endpoints) == null ? void 0 : _a.getCategories, "wp-json/wp/v2/categories"),
81081+
getUrl((_a = this.context.endpoints) == null ? void 0 : _a.getCategories, "wp-json/wp/v2/categories?per_page=100"),
8108781082
{
8108881083
headers: this.context.getHeaders(certificate)
8108981084
}
@@ -81104,7 +81099,7 @@ var WpRestClient = class extends AbstractWordPressClient {
8110481099
var _a;
8110581100
try {
8110681101
const data = await this.client.httpGet(
81107-
getUrl((_a = this.context.endpoints) == null ? void 0 : _a.validateUser, `wp-json/wp/v2/users?search=xxx`),
81102+
getUrl((_a = this.context.endpoints) == null ? void 0 : _a.validateUser, `wp-json/wp/v2/users/me`),
8110881103
{
8110981104
headers: this.context.getHeaders(certificate)
8111081105
}

src/abstract-wp-client.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,17 @@ export abstract class AbstractWordPressClient implements WordPressClient {
203203
const images = getImages(postParams.content);
204204
for (const img of images) {
205205
if (!img.srcIsUrl) {
206-
const splitFile = img.src.split('.');
207-
const ext = splitFile.pop();
208-
const fileName = splitFile.join('.');
209-
// @ts-expect-error
210-
let filePath = (await this.plugin.app.vault.getAvailablePathForAttachments(
211-
fileName,
212-
ext,
213-
activeFile
214-
)) as string;
215-
const pathRegex = /(.*) \d+\.(.*)/;
216-
filePath = filePath.replace(pathRegex, '$1.$2');
217-
const imgFile = this.plugin.app.vault.getAbstractFileByPath(filePath);
206+
207+
img.src = decodeURI(img.src);
208+
const fileName = img.src.split("/").pop();
209+
210+
if ( fileName === undefined )
211+
continue;
212+
213+
let normPath = this.plugin.app.metadataCache.getFirstLinkpathDest(img.src, fileName);
214+
215+
const imgFile = normPath;
216+
218217
if (imgFile instanceof TFile) {
219218
const content = await this.plugin.app.vault.readBinary(imgFile);
220219
const fileType = fileTypeChecker.detectFile(content);

src/wp-rest-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class WpRestClient extends AbstractWordPressClient {
125125
async validateUser(certificate: WordPressAuthParams): Promise<WordPressClientResult<boolean>> {
126126
try {
127127
const data = await this.client.httpGet(
128-
getUrl(this.context.endpoints?.validateUser, `wp-json/wp/v2/users?search=xxx`),
128+
getUrl(this.context.endpoints?.validateUser, `wp-json/wp/v2/users/me`),
129129
{
130130
headers: this.context.getHeaders(certificate)
131131
});

0 commit comments

Comments
 (0)