public static async Task <bool> DeleteTrackFollow(string userId, string trackId, bool ownerOverride = false) { try { TrackAuth track = await TrackRepository.GetTrack(trackId); if (track.PartitionKey == userId && ownerOverride == false) { return(false); } UserFollowTableEntity userFollow = await TableStorageRepository.GetUserFollow(userId, trackId); TrackFollowTableEntity trackFollow = await TableStorageRepository.GetTrackFollow(trackId, userId); if (userFollow != null) { await TableStorageRepository.DeleteUserFollow(userFollow); } if (trackFollow != null) { await TableStorageRepository.DeleteTrackFollow(trackFollow); } return(true); } catch { return(false); } }
public static async Task <string> GenerateRefreshToken(string userId) { // create var token = GenerateSHA256(userId + Tools.ConvertToEpoch(DateTime.UtcNow).ToString()); // insert to db await TableStorageRepository.InsertRefreshToken(new RefreshToken(userId, token)); return(EncodeKeyAndSecret(userId, token)); }
public static async Task <TrackAuth> GetTrack(string trackId) { var track = await TableStorageRepository.GetTrack(trackId); if (track == null) { return(null); } return(track); }
private static async void InsertOrReplaceUserFollow(string userId, string trackId) { TrackAuth track = await TrackRepository.GetTrack(trackId); TableStorageRepository.InsertOrReplaceUserFollow(new UserFollowTableEntity(userId, trackId) { description = track.description, has_image = track.has_image, is_private = track.is_private, name = track.name }); }
public static async Task <PostReturnObject> GetPosts(PostQuery query) { List <PostQueryDTO> data = await TableStorageRepository.GetPosts(query); string continuation = data.Count > 1 ? data[data.Count - 1].date_created.ToString() : null; return(new PostReturnObject() { continuation = continuation, count = data.Count, data = data }); }
public static async Task <List <TrackFollow> > GetTrackFollows(string trackId, Enums.FollowMode followMode = Enums.FollowMode.Feed) { List <TrackFollowTableEntity> results = await TableStorageRepository.GetTrackFollows(trackId, followMode); List <TrackFollow> trackFollows = new List <TrackFollow>(); foreach (TrackFollowTableEntity result in results) { trackFollows.Add(TableEntityToTrackFollow(result)); } return(trackFollows); }
// table storage stuff public static async Task <Post> InsertPost(PostSubmitDTO postDTO) { long now = Tools.ConvertToEpoch(DateTime.UtcNow); long countdown = Tools.GetCountdownFromDateTime(now); string id = countdown.ToString() + Guid.NewGuid().ToString(); Post post = new Post(id, postDTO.track_id) { body = postDTO.body, url = postDTO.url, summary = postDTO.summary, date_created = now, track_name = postDTO.track_name, tags = string.Join(",", postDTO.tags), title = postDTO.title, type = postDTO.type, has_image = false }; // TODO: process image if (Tools.ValidateUri(postDTO.image_url)) { post.has_image = await ProcessImage(id, postDTO.image_url); } var result = await TableStorageRepository.InsertPost(post); if (result == null) { return(null); } // shit hack to remove body for queue processing post.body = null; // add to queues for further processing TableStorageRepository.AddMessageToQueue("process-new-post-increment-track-tags", JsonConvert.SerializeObject(post)); TableStorageRepository.AddMessageToQueue("process-new-post-add-to-cosmos", JsonConvert.SerializeObject(post)); // check rate limit Random rnd = new Random(); if (rnd.Next(1, 8) == 3) { TableStorageRepository.AddMessageToQueue("process-new-post-check-rate-limit", post.PartitionKey); } return(post); }
public static async Task <TrackAuth> CreateTrack(TrackAuth track) { if (track.PartitionKey == null || track.name == null) { return(null); } var extendedUser = await ExtendedUserRepository.GetExtendedUser(track.PartitionKey); // check private maxed out if (track.is_private) { if (extendedUser.Private_Tracks >= extendedUser.Private_Tracks_Max) { return(null); } } // check public maxed out if (!track.is_private) { if (extendedUser.Public_Tracks >= extendedUser.Public_Tracks_Max) { return(null); } } track.RowKey = track.RowKey ?? Guid.NewGuid().ToString(); track.subscribers = 0; track.rate_limit = extendedUser.Rate_Per_Track; track.track_key = AuthRepository.GenerateRandomString(64); track.track_secret = AuthRepository.GenerateSHA256(track.RowKey + track.track_key); // insert into table storage var newTrack = await TableStorageRepository.InsertTrackAuth(track); if (newTrack == null) { return(null); } // insert into Cosmos await(dynamic) CosmosRepository <Track> .CreateItemAsync(new Track(track)); // increment user's track count ExtendedUserRepository.IncrementTrackCount(track.PartitionKey, track.is_private); return(newTrack); }
public static async Task <string> GetRefreshTokenUserAndDestroyToken(string encodedToken) { KeySecret keySecret = DecodeKeyAndSecret(encodedToken); var refreshToken = await TableStorageRepository.GetRefreshToken(keySecret.Key, keySecret.Secret); if (refreshToken == null) { return(null); } TableStorageRepository.DeleteRefreshToken(refreshToken); return(keySecret.Key); }
public static async Task <TrackAuth> GetTrackVerifyOwner(string trackId, string userId) { var track = await TableStorageRepository.GetTrack(trackId); if (track == null) { return(null); } if (track.PartitionKey != userId) { return(null); } return(track); }
public static async Task <bool> DeleteTrack(string trackId) { // decrement the count var track = await GetTrack(trackId); ExtendedUserRepository.DecrementTrackCount(track.PartitionKey, track.is_private); // send messages to queue TableStorageRepository.AddMessageToQueue("delete-posts-from-track", trackId); TableStorageRepository.AddMessageToQueue("delete-tracktags-from-track", trackId); // then delete track cosmos CosmosRepository <Track> .DeleteItemAsync(trackId); // then delete profile pics DeleteImages(trackId); // then delete from table storage, and return return(await TableStorageRepository.DeleteTrack(trackId)); }
public static async Task <List <TrackDTO> > GetUserFollows(string userId) { var results = await TableStorageRepository.GetUserFollows(userId); List <TrackDTO> tracks = new List <TrackDTO>(); foreach (var result in results) { tracks.Add(new TrackDTO() { id = result.RowKey, name = result.name, description = result.description, has_image = result.has_image, is_private = result.is_private }); } return(tracks.OrderBy(t => t.name).ToList()); }
public static void InsertOrReplaceTrackFollow(TrackFollow trackFollow) { // check user and track id if (trackFollow?.user_id == null || trackFollow?.track_id == null) { return; } // validate criteria List <TagCriteria> validatedTagCriteria = new List <TagCriteria>(); // ensure the follow is in the user follow table toowoo woo InsertOrReplaceUserFollow(trackFollow.user_id, trackFollow.track_id); if (trackFollow.criteria != null && trackFollow.criteria.Count > 0) { foreach (var criterion in trackFollow.criteria.Take(12)) { criterion.feed = trackFollow.feed_follow_type != null ? false : criterion.feed; criterion.notifications = trackFollow.notifications_follow_type != null ? false : criterion.notifications; TagCriteria validatedCriterion = ValidateTagCriteria(criterion); if (validatedCriterion != null) { validatedTagCriteria.Add(validatedCriterion); } } } trackFollow.criteria = validatedTagCriteria; // get basic follow modes trackFollow.feed_follow_type = trackFollow.feed_follow_type == "all" || trackFollow.feed_follow_type == "none" ? trackFollow.feed_follow_type : GetFollowType(trackFollow.criteria, Enums.FollowMode.Feed); trackFollow.notifications_follow_type = trackFollow.notifications_follow_type == "all" || trackFollow.notifications_follow_type == "none" ? trackFollow.notifications_follow_type : GetFollowType(trackFollow.criteria, Enums.FollowMode.Notification); TableStorageRepository.InsertOrReplaceTrackFollow(TrackFollowToTableEntity(trackFollow)); }
public static async Task <TrackFollow> GetTrackFollow(string trackId, string userId) { TrackFollowTableEntity result = await TableStorageRepository.GetTrackFollow(trackId, userId); return(TableEntityToTrackFollow(result)); }
public static void InsertOrIncrementTrackTag(TrackTag trackTag) { TableStorageRepository.InsertOrIncrementTrackTag(trackTag); }
public static async Task <List <string> > GetPostIdsInTrack(string trackId) { return(await TableStorageRepository.GetPostIdsInTrack(trackId)); }
public static void DeletePostFromTableStorage(Post postMeta) { TableStorageRepository.DeletePost(postMeta); }
public static async Task <Post> GetPost(string trackId, string postId) { return(await TableStorageRepository.GetPost(trackId, postId)); }
public static async Task <int> PostsLastHourCount(string trackId) { return(await TableStorageRepository.GetPostCountSince(trackId, 60)); }
/// <summary> /// Get tracks by ownerId. /// </summary> /// <param name="ownerId"></param> /// <returns>List of tracks.</returns> public static async Task <List <TrackAuth> > GetTracksByOwnerId(string ownerId) { List <TrackAuth> tracks = await TableStorageRepository.GetTracksByOwnerId(ownerId); return(tracks); }
public static void DeleteTrackTag(TrackTag trackTag) { TableStorageRepository.DeleteTrackTag(trackTag); }
public static async Task <ExtendedUser> GetExtendedUser(string userId) { return(await TableStorageRepository.GetExtendedUser(userId)); }
public static async Task <List <TrackAuth> > GetRateLimitedTracks() { return(await TableStorageRepository.GetRateLimitedTracks()); }
public static void UpdateTrack(TrackAuth track) { TableStorageRepository.UpdateTrack(track); }
public static async Task <ExtendedUser> UpdateExtendedUser(ExtendedUser user) { return(await TableStorageRepository.UpdateExtendedUser(user)); }
public static async Task <List <TrackTag> > GetTagsByTrack(string trackId) { return(await TableStorageRepository.GetTagsByTrack(trackId)); }