summary refs log tree commit diff
path: root/LibGitTest/WebRepoSource.cs
blob: 39d9b797add4dbb98c23f8a4fc9c9c122c2e211a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using LibGit.Interfaces;

namespace LibGitTest;

public class WebRepoSource : IRepoSource
{
    private const bool _debug = false;
    public WebRepoSource(string basePath)
    {
        BasePath = basePath;
    }

    public string BasePath { get; set; }

    public async Task<Stream> GetFileStream(string path)
    {
        var client = new HttpClient();
        if(_debug)Console.WriteLine("Fetching file: " + Path.Join(BasePath, path));
        var response = await client.GetAsync(Path.Join(BasePath, path));
        if(!response.IsSuccessStatusCode) throw new Exception("Failed to fetch file: " + Path.Join(BasePath, path));
        return await response.Content.ReadAsStreamAsync();
    }

    public async Task<bool> HasObjectCached(string currentCommitId)
    {
        return Random.Shared.Next(0, 2) == 1;
    }
}