Add project files.
This commit is contained in:
7
OfflineDemo/Pages/Home.razor
Normal file
7
OfflineDemo/Pages/Home.razor
Normal file
@ -0,0 +1,7 @@
|
||||
@page "/"
|
||||
|
||||
<PageTitle>Home</PageTitle>
|
||||
|
||||
<h1>Hello, world!</h1>
|
||||
|
||||
Welcome to your new app.
|
||||
62
OfflineDemo/Pages/TikTokList.razor
Normal file
62
OfflineDemo/Pages/TikTokList.razor
Normal file
@ -0,0 +1,62 @@
|
||||
@page "/shorts"
|
||||
|
||||
@inject HttpClient httpClient
|
||||
@inject IConfiguration config
|
||||
|
||||
<h3>Shorts List</h3>
|
||||
|
||||
@if (shorts == null)
|
||||
{
|
||||
<p>Loading...</p>
|
||||
}
|
||||
else if (!shorts.Any())
|
||||
{
|
||||
<p>No shorts available.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Title</th>
|
||||
<th>Description</th>
|
||||
<th>Hashtags</th>
|
||||
<th>Mp4 URL</th>
|
||||
<th>Image URL</th>
|
||||
<th>Uploaded</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var shortItem in shorts)
|
||||
{
|
||||
<tr>
|
||||
<td>@shortItem.Id</td>
|
||||
<td>@shortItem.Title</td>
|
||||
<td>@shortItem.Description</td>
|
||||
<td>@shortItem.Hashtags</td>
|
||||
<td><a href="@shortItem.Mp4FileUrl" target="_blank">View Video</a></td>
|
||||
<td><a href="@shortItem.ImageFileUrl" target="_blank">View Image</a></td>
|
||||
<td>@(shortItem.IsUploaded ? "Yes" : "No")</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
|
||||
@code {
|
||||
private List<ShortsModel>? shorts;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
string url = $"{config["ApiUrl"]}/shorts";
|
||||
shorts = await httpClient.GetFromJsonAsync<List<ShortsModel>>(url);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"Error fetching shorts: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
138
OfflineDemo/Pages/TikTokUpload.razor
Normal file
138
OfflineDemo/Pages/TikTokUpload.razor
Normal file
@ -0,0 +1,138 @@
|
||||
@page "/upload"
|
||||
@using Microsoft.AspNetCore.Components.Forms
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@inject HttpClient http
|
||||
@inject IConfiguration config
|
||||
@inject NavigationManager nav
|
||||
|
||||
<h3>Upload TikTok Video</h3>
|
||||
|
||||
@if (isSubmitting)
|
||||
{
|
||||
<p>Uploading...</p>
|
||||
}
|
||||
|
||||
@if (!string.IsNullOrEmpty(resultMessage))
|
||||
{
|
||||
<p>@resultMessage</p>
|
||||
}
|
||||
|
||||
<EditForm Model="@uploadModel" OnValidSubmit="@HandleValidSubmit">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary />
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label class="form-label" for="title">Title</label>
|
||||
<InputText id="title" class="form-control" @bind-Value="uploadModel.Title" />
|
||||
<ValidationMessage For="@(() => uploadModel.Title)" />
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label class="form-label" for="description">Description</label>
|
||||
<InputTextArea id="description" class="form-control" @bind-Value="uploadModel.Description" />
|
||||
<ValidationMessage For="@(() => uploadModel.Description)" />
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label class="form-label" for="hashtags">Hashtags</label>
|
||||
<InputText id="hashtags" @oninput="HandleHashtagInput" class="form-control" @bind-Value="uploadModel.Hashtags" />
|
||||
<ValidationMessage For="@(() => uploadModel.Hashtags)" />
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label class="form-label" for="mp4Upload">MP4 File</label>
|
||||
<InputFile id="mp4Upload" class="form-control" OnChange="@HandleMp4FileChange" accept=".mp4,.mov" />
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-3">
|
||||
<label class="form-label" for="imageUpload">Image File (optional)</label>
|
||||
<InputFile id="imageUpload" class="form-control" OnChange="@HandleImageFileChange" accept=".jpg,.jpeg,.png" />
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</EditForm>
|
||||
|
||||
@code {
|
||||
private UploadModel uploadModel = new();
|
||||
private IBrowserFile? mp4File;
|
||||
private IBrowserFile? imageFile;
|
||||
private bool isSubmitting = false;
|
||||
private string? resultMessage;
|
||||
|
||||
private void HandleMp4FileChange(InputFileChangeEventArgs e)
|
||||
{
|
||||
mp4File = e.File;
|
||||
}
|
||||
|
||||
private void HandleImageFileChange(InputFileChangeEventArgs e)
|
||||
{
|
||||
imageFile = e.File;
|
||||
}
|
||||
|
||||
private async Task HandleHashtagInput(ChangeEventArgs e)
|
||||
{
|
||||
var input = e.Value?.ToString() ?? "";
|
||||
if (input.EndsWith(" "))
|
||||
{
|
||||
// Add a hashtag before the space
|
||||
uploadModel.Hashtags = input.TrimEnd() + " #";
|
||||
// Optionally, reset cursor position
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleValidSubmit()
|
||||
{
|
||||
resultMessage = "";
|
||||
|
||||
if (mp4File == null || imageFile == null)
|
||||
{
|
||||
resultMessage = "Both MP4 and Image files are required.";
|
||||
return;
|
||||
}
|
||||
|
||||
isSubmitting = true;
|
||||
|
||||
try
|
||||
{
|
||||
using var content = new MultipartFormDataContent();
|
||||
content.Add(new StringContent(uploadModel.Title ?? string.Empty), "Title");
|
||||
content.Add(new StringContent(uploadModel.Description ?? string.Empty), "Description");
|
||||
content.Add(new StringContent(uploadModel.Hashtags ?? string.Empty), "Hashtags");
|
||||
|
||||
// Add files
|
||||
var mp4Stream = mp4File.OpenReadStream(800 * 1024 * 1024); // 800 MB limit
|
||||
var mp4Content = new StreamContent(mp4Stream);
|
||||
mp4Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(mp4File.ContentType);
|
||||
content.Add(mp4Content, "Mp4File", mp4File.Name);
|
||||
|
||||
var imageStream = imageFile.OpenReadStream(10 * 1024 * 1024); // 10 MB limit for images
|
||||
var imageContent = new StreamContent(imageStream);
|
||||
imageContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(imageFile.ContentType);
|
||||
content.Add(imageContent, "ImageFile", imageFile.Name);
|
||||
|
||||
// Call the API
|
||||
string url = $"{config["ApiUrl"]}/upload";
|
||||
var response = await http.PostAsync(url, content);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
resultMessage = "Files uploaded successfully!";
|
||||
nav.NavigateTo("/shorts");
|
||||
}
|
||||
else
|
||||
{
|
||||
var error = await response.Content.ReadAsStringAsync();
|
||||
resultMessage = $"Error: {response.StatusCode} - {error}";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
resultMessage = $"An error occurred: {ex.Message}";
|
||||
}
|
||||
finally
|
||||
{
|
||||
isSubmitting = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
49
OfflineDemo/Pages/ToDo.razor
Normal file
49
OfflineDemo/Pages/ToDo.razor
Normal file
@ -0,0 +1,49 @@
|
||||
@page "/todo"
|
||||
@inject ILocalStorageService localStorage
|
||||
|
||||
<h3>ToDo</h3>
|
||||
|
||||
@if (todos is not null)
|
||||
{
|
||||
<ol>
|
||||
@foreach (var todo in todos)
|
||||
{
|
||||
<li>@todo.ToDoItem (@todo.CreationDate.ToString("MMMM dd, yyyy hh:mm tt"))</li>
|
||||
}
|
||||
</ol>
|
||||
}
|
||||
|
||||
<h4>Add ToDo Item</h4>
|
||||
<EditForm Model="newTodo" OnValidSubmit="AddTodo">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary />
|
||||
<div class="form-group">
|
||||
<label for="newTodo.ToDoItem">ToDo Item</label>
|
||||
<InputText id="newTodo.ToDoItem" class="form-control" @bind-Value="newTodo.ToDoItem" />
|
||||
<ValidationMessage For="@(() => newTodo.ToDoItem)" />
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Add</button>
|
||||
</EditForm>
|
||||
|
||||
@code {
|
||||
private List<TodoModel> todos;
|
||||
private TodoModel newTodo = new();
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
todos = await localStorage.GetItemAsync<List<TodoModel>>("todos");
|
||||
|
||||
if (todos is null || todos.Count == 0)
|
||||
{
|
||||
todos = new();
|
||||
await localStorage.SetItemAsync("todos", todos);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task AddTodo()
|
||||
{
|
||||
todos.Add(newTodo);
|
||||
newTodo = new();
|
||||
await localStorage.SetItemAsync("todos", todos);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user