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

开发计划:通过调用同步接口来触发同步 #2

Open
cssmagic opened this issue May 20, 2022 · 4 comments
Open

开发计划:通过调用同步接口来触发同步 #2

cssmagic opened this issue May 20, 2022 · 4 comments
Labels

Comments

@cssmagic
Copy link
Owner

背景

目前是借助了镜像网站的同步网页来触发同步,需要弹出浏览器,离开了命令行界面,体验不够顺畅。

计划

调研同步接口,参考 cnpm sync 的源码,摆脱对浏览器的依赖,从而实现所有交互在命令行完成。

@champkeh
Copy link

champkeh commented Jun 1, 2022

感觉不需要看cnpm源码,我看了一下浏览器请求,同步的时候就是去请求了一个 https://registry-direct.npmmirror.com/[PKG_NAME]/sync?sync_upstream=true ,然后拿到一个logId,然后根据这个id轮训去请求https://registry-direct.npmmirror.com/[PKG_NAME]/sync/log/[logId] ,然后检查返回的syncDone字段,true则表示同步完成

因此,只需要发几个请求就可以了,也不需要打开浏览器了。

@cssmagic
Copy link
Owner Author

cssmagic commented Jun 6, 2022

@champkeh
好的,谢谢提示!

@champkeh
Copy link

champkeh commented Jun 7, 2022

哈哈,根据这个思路,我也写了一个自动同步的工具sync-npm-mirror

@cssmagic
Copy link
Owner Author

cssmagic commented Jun 8, 2022

@champkeh
哈哈,不错不错,很荣幸能给你启发。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants