Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

希望支持自定义web版本agenda链接本地server的地址 #290

Open
1 of 2 tasks
jiagoumengxiang opened this issue Feb 23, 2024 · 1 comment
Open
1 of 2 tasks
Labels
enhancement New feature or request

Comments

@jiagoumengxiang
Copy link

Search first

  • I searched and no similar issues were found

What Happened?

电脑和平板在同一个局域网里面。 想从平板上看agenda,电脑上使用笔记

Reproduce the Bug

现在没找到能修改server地址的地方

Screenshots

No response

Environment Information

No response

Additional Context

No response

Are you willing to submit a PR? If you know how to fix the bug.

  • I'm willing to submit a PR (Thank you!)
@moulai
Copy link

moulai commented Mar 7, 2024

附议。同需要这个功能。

目前靠自己架设一个Agenda网页勉强实现,参考:https://github.com/haydenull/logseq-plugin-agenda/tree/main?tab=readme-ov-file

  1. 将Logseq API的Host地址由127.0.0.1改为0.0.0.0。
  2. 然后修改.env文件里的VITE_LOGSEQ_API_SERVER为电脑IP。
  3. 还要修改vite.config.ts,加上:
    test: {
      globals: true,
      environment: 'jsdom',
      setupFiles: ['./src/tests/setupTest.ts'],
    },
    server: { // 添加的部分开始
      host: '0.0.0.0',
      port: 自行修改,
      https: false, // 关闭HTTPS支持(可选)
    }, // 添加的部分结束
  }
})
  1. (可选)修改src/services/ics.ts,本地实现上传ics到github的功能(否则上传ics会被跨域访问拒绝)。
interface GithubContentResponse {
  sha: string;
}

export const uploadIcsHttp = async ({ repo, token, file }: { repo: string; token: string; file: string }) => {
  const base64File = window.btoa(unescape(encodeURIComponent(file)));

  let sha;
  try {
    const response = await fetch(`https://api.github.com/repos/${repo}/contents/agenda.ics`, {
      headers: {
        'Authorization': `token ${token}`,
      },
    });
    const data = await response.json() as GithubContentResponse;
    sha = data.sha;
  } catch (err) {
    console.log('Failed to get file SHA:', err);
  }

  const date = new Date();
  const commitTitle = `[Local Agenda]: update agenda.ics ${date.toLocaleDateString('en-US', { timeZone: 'UTC' })}, ${date.toLocaleTimeString('en-US', { timeZone: 'UTC' })}`;

  return new Promise((resolve, reject) => {
    fetch(`https://api.github.com/repos/${repo}/contents/agenda.ics`, {
      method: 'PUT',
      headers: {
        'Authorization': `token ${token}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        message: commitTitle,
        content: base64File,
        ...(sha && { sha }),
      }),
    })
      .then(async (response) => {
        console.log('upload ics response', response)
        const data = (await response.json()) as { message: string }
        if (!response.ok) {
          reject(data)
        }
        resolve(data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

@haydenull haydenull added the enhancement New feature or request label Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants