Nb
Study
.com
🔍 请输入搜索关键字

Windows 子系统中配置 Rust国内镜像以解决cargo run太慢的问题

Cargo则是Rust的官方包管理工具。在进行Rust项目开发时,由于网络原因,从Crates.io下载依赖可能会很慢。为此可以配置Cargo使用国内的镜像源。

在 Windows 子系统的 Linux 发行版中,打开终端,在用户主目录下找到.cargo文件夹,若不存在可新建。在该文件夹中创建或编辑config文件,添加国内镜像源配置内容:

配置国内镜像源

bash 复制代码
[source.crates-io]
replace-with = 'aliyun'
[source.aliyun]
registry = "sparse+https://mirrors.aliyun.com/crates.io-index/"
[source.ustc]
registry = "https://mirrors.ustc.edu.cn/crates.io-index"
[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index/"
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
[source.rustcc]
registry = "https://code.aliyun.com/rustcc/crates.io-index.git"                                                             

清理 Cargo 缓存

删除.cargo目录下的.package-cache文件:

bash 复制代码
rm $HOME/.cargo/.package-cache

使用config.toml

如果是rust 1.38 及以后的版本,推荐 使用config.toml 代替 config
否则会有一下警告。

即:

toml 复制代码
[source]
[source.crates-io]
replace-with = "aliyun"

[source.aliyun]
registry = "sparse+https://mirrors.aliyun.com/crates.io-index/"

[source.ustc]
registry = "https://mirrors.ustc.edu.cn/crates.io-index"

[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index/"

[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"

[source.rustcc]
registry = "https://code.aliyun.com/rrustcc/crates.io-index.git"

注意,toml 配置的写法稍有不同。

如何在线查看mp4视频的编码格式,是否为iOS兼容的h264格式

记录一下,可以在线查询mp4编码格式的网站:

https://gpac.github.io/mp4box.js/test/filereader.html

通常H264的格式的文件编码信息如下:

Movie Info

File Size / Bitrate: 0 bytes / 0 kbps
Duration / Timescale: 220845/1000 (0:03:40.845)
Brands (major/compatible): isom,isom,iso2,avc1,mp41
MIME: video/mp4; codecs="avc1.42c01f,mp4a.40.2"; profiles="isom,iso2,avc1,mp41"
Progressive: false
Fragmented: false
MPEG-4 IOD: false

重点查看MIME类型是否为video/mp4,是否包含avc信息。且 Progressive/Fragmented/MPEG-4 IOD 三个参数为false。

另外iOS支持的编码格式可以通过官方查看:
https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/StreamingMediaGuide/FrequentlyAskedQuestions/FrequentlyAskedQuestions.html

What are the specifics of the video and audio formats supported?
Although the protocol specification does not limit the video and audio formats, the current Apple implementation supports the following formats:

  • Video:
    H.264 Baseline Level 3.0, Baseline Level 3.1, Main Level 3.1, and High Profile Level 4.1.

  • Audio:
    HE-AAC or AAC-LC up to 48 kHz, stereo audio
    MP3 (MPEG-1 Audio Layer 3) 8 kHz to 48 kHz, stereo audio
    AC-3 (for Apple TV, in pass-through mode only)

npm报错:request to https://registry.npm.taobao.org failed, reason certificate has expired

最新一个老项目,在使用 npm install 时, 总是报错:

npm报错:request to https://registry.npm.taobao.org failed, reason certificate has expired

很明显原因是淘宝镜像过期了!

通过npm config get registry 查询本地的npm镜像:

bash 复制代码
apple@AppledeMacBook-Pro h5 % npm config get registry                                              
https://registry.npmmirror.com/

发现明明已经切换到新的镜像了啊,为什么还是报错呢?

原因是项目本地的package-lock.json 文件导致的,删除即可。

axios的withCredentials到底是什么意思?

通常我们使用以下代码创建一个axios实例。

javascript 复制代码
const axiosInstance = axios.create({
  baseURL:import.meta.env.AXIOS_BASE_URL as string,
  withCredentials: true,
  timeout: 55000,
});

那上述代码中的withCredentials 是什么意思呢?

withCredentialsXMLHttpRequest 对象的一个属性。

axios也是XMLHttpRequest的封装,当然最新的axios版本底层也支持fetch了。

withCredentials用于指示是否应该允许跨域请求携带凭据(如Cookies、HTTP认证信息、客户端SSL证明等)。当设置为 true 时,它允许跨域请求发送凭据,但同时也要求服务器端必须正确响应CORS(跨源资源共享)策略

详解 withCredentials:

1. 默认值:withCredentials 的默认值是 false。

这意味着,除非显式设置为 true,否则跨域请求不会携带凭据。

当你设置 XMLHttpRequest 的 withCredentials 属性为 true 时,你告诉浏览器在发送跨域请求时携带凭据。例如:

javascript 复制代码
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

2. 服务器端响应:

当 withCredentials 设置为 true 时,服务器必须在其CORS响应头中包含 Access-Control-Allow-Credentials: true,以允许浏览器接受带有凭据的请求。同时,Access-Control-Allow-Origin 不能设置为通配符 *,而必须指定明确的源

3. 安全性考虑:

允许跨域请求携带凭据可能会带来安全风险,因为它允许第三方网站访问敏感的用户数据。因此,只有当你完全信任目标源,并且需要在请求中包含用户凭据时,才应该将 withCredentials 设置为 true。

4. 现代浏览器和Fetch API:
在现代浏览器中,fetch API 也支持跨域请求。当使用 fetch 发起跨域请求时,可以通过设置 credentials: 'include' 来达到与 XMLHttpRequest 中 withCredentials: true 相同的效果。