mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.4 KiB
50 lines
1.4 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
|
|
namespace Squidex.Domain.Apps.Entities.Backup.Archive
|
|
{
|
|
public static class ArchiveHelper
|
|
{
|
|
private const int MaxAttachmentFolders = 1000;
|
|
private const int MaxEventsPerFolder = 1000;
|
|
|
|
public static string GetAttachmentPath(string name)
|
|
{
|
|
name = name.ToLowerInvariant();
|
|
|
|
var attachmentFolder = SimpleHash(name) % MaxAttachmentFolders;
|
|
var attachmentPath = $"attachments/{attachmentFolder}/{name}";
|
|
|
|
return attachmentPath;
|
|
}
|
|
|
|
public static string GetEventPath(int index)
|
|
{
|
|
var eventFolder = index / MaxEventsPerFolder;
|
|
var eventPath = $"events/{eventFolder}/{index}.json";
|
|
|
|
return eventPath;
|
|
}
|
|
|
|
private static int SimpleHash(string value)
|
|
{
|
|
var hash = 17;
|
|
|
|
foreach (char c in value)
|
|
{
|
|
unchecked
|
|
{
|
|
hash = (hash * 23) + c.GetHashCode();
|
|
}
|
|
}
|
|
|
|
return Math.Abs(hash);
|
|
}
|
|
}
|
|
}
|
|
|