Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tidusjar committed Mar 27, 2018
2 parents 7baf015 + 39344d2 commit a003095
Show file tree
Hide file tree
Showing 162 changed files with 5,216 additions and 677 deletions.
78 changes: 78 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,83 @@
# Changelog

## v3.0.3020 (2018-03-13)

### **New Features**

- Added the Recently Added Newsletter! You are welcome. [tidusjar]

- Added a new scrollbar to Ombi. [tidusjar]

- Added the ability to automatically generate the API Key on startup if it does not exist #2070. [tidusjar]

- Updated npm dependancies. [Jamie]

- Update README.md. [Jamie]

- Update README.md. [Jamie]

- Update ISSUE_TEMPLATE.md. [Jamie]

- Update appveyor.yml. [Jamie]

- Added recently added stuff. [Jamie]

- Added the recently added engine with some basic methods. [Jamie]

- Added the ability to refresh out backend metadata (#2078) [Jamie]

### **Fixes**

- Specific favicons for different platforms. [louis-lau]

- MovieDbId was switched to string fron number so accomodated for change. [Anojh]

- Removing duplicate functions. [Anojh Thayaparan]

- Conflict resolving and adopting Jamie's new method. [Anojh]

- Wrote new calls to just get poster and bg. [Anojh]

- Fix for issue #1907, which is to add content poster and bg to issue details page. [Anojh]

- Dynamic Background Animation. [Anojh]

- Improved the message for #2037. [tidusjar]

- Improved the way we use the notification variables, we have now split out the Username and Alias (Requested User is depricated but not removed) [tidusjar]

- Removed redundant timers. [Anojh]

- More optimizations by reducing requests. [Anojh]

- Improved version. [Anojh]

- Dynamic Background Animation. [Anojh]

- Fixed #2055 and #1903. [Jamie]

- Small changes to the auto updater, let's see how this works. [Jamie]

- Fixed build. [Jamie]

- Fixed the update check for the master build. [Jamie]

- Fixed build. [Jamie]

- Fixed #2074 and #2079. [Jamie]


## v3.0.3030 (2018-03-14)

### **New Features**

- Updated the .Net core dependancies #2072. [Jamie]

### **Fixes**

- Delete Ombi.testdb. [Jamie]


## v3.0.3020 (2018-03-13)

### **Fixes**
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ ____
___


[![Report a bug](http://i.imgur.com/xSpw482.png)](https://forums.ombi.io/viewforum.php?f=10) [![Feature request](http://i.imgur.com/mFO0OuX.png)](https://forums.ombi.io/posting.php?mode=post&f=20)


| Service | Stable | Develop |
|----------|:---------------------------:|:----------------------------:|
| AppVeyor | [![Build status](https://ci.appveyor.com/api/projects/status/hgj8j6lcea7j0yhn/branch/master?svg=true)](https://ci.appveyor.com/project/tidusjar/requestplex/branch/master) | [![Build status](https://ci.appveyor.com/api/projects/status/hgj8j6lcea7j0yhn/branch/develop?svg=true)](https://ci.appveyor.com/project/tidusjar/requestplex/branch/develop) |
Expand Down
4 changes: 2 additions & 2 deletions src/Ombi.Api.FanartTv/FanartTvApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public async Task<TvResult> GetTvImages(int tvdbId, string token)
}
}

public async Task<MovieResult> GetMovieImages(int theMovieDbId, string token)
public async Task<MovieResult> GetMovieImages(string movieOrImdbId, string token)
{
var request = new Request($"movies/{theMovieDbId}", Endpoint, HttpMethod.Get);
var request = new Request($"movies/{movieOrImdbId}", Endpoint, HttpMethod.Get);
request.AddHeader("api-key", token);

return await Api.Request<MovieResult>(request);
Expand Down
2 changes: 1 addition & 1 deletion src/Ombi.Api.FanartTv/IFanartTvApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Ombi.Api.FanartTv
{
public interface IFanartTvApi
{
Task<MovieResult> GetMovieImages(int theMovieDbId, string token);
Task<MovieResult> GetMovieImages(string movieOrImdbId, string token);
Task<TvResult> GetTvImages(int tvdbId, string token);
}
}
2 changes: 1 addition & 1 deletion src/Ombi.Api.Mattermost/IMattermostApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ namespace Ombi.Api.Mattermost
{
public interface IMattermostApi
{
Task<string> PushAsync(string webhook, MattermostBody message);
Task PushAsync(string webhook, MattermostMessage message);
}
}
10 changes: 3 additions & 7 deletions src/Ombi.Api.Mattermost/MattermostApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@ public MattermostApi(IApi api)

private readonly IApi _api;

public async Task<string> PushAsync(string webhook, MattermostBody message)
public async Task PushAsync(string webhook, MattermostMessage message)
{
var request = new Request(string.Empty, webhook, HttpMethod.Post);

request.AddJsonBody(message);

var result = await _api.RequestContent(request);
return result;
var client = new MatterhookClient(webhook);
await client.PostAsync(_api, message);
}
}
}
168 changes: 168 additions & 0 deletions src/Ombi.Api.Mattermost/Models/MattermostClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
///
///
///
/// Code taken from https://github.com/PromoFaux/Matterhook.NET.MatterhookClient
///
///
///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace Ombi.Api.Mattermost.Models
{
public class MatterhookClient
{
private readonly Uri _webhookUrl;
private readonly HttpClient _httpClient = new HttpClient();

/// <summary>
/// Create a new Mattermost Client
/// </summary>
/// <param name="webhookUrl">The URL of your Mattermost Webhook</param>
/// <param name="timeoutSeconds">Timeout Value (Default 100)</param>
public MatterhookClient(string webhookUrl, int timeoutSeconds = 100)
{
if (!Uri.TryCreate(webhookUrl, UriKind.Absolute, out _webhookUrl))
throw new ArgumentException("Mattermost URL invalid");

_httpClient.Timeout = new TimeSpan(0, 0, 0, timeoutSeconds);
}

public MattermostMessage CloneMessage(MattermostMessage inMsg)
{
var outMsg = new MattermostMessage
{
Text = "",
Channel = inMsg.Channel,
Username = inMsg.Username,
IconUrl = inMsg.IconUrl
};

return outMsg;
}

private static MattermostAttachment CloneAttachment(MattermostAttachment inAtt)
{
var outAtt = new MattermostAttachment
{
AuthorIcon = inAtt.AuthorIcon,
AuthorLink = inAtt.AuthorLink,
AuthorName = inAtt.AuthorName,
Color = inAtt.Color,
Fallback = inAtt.Fallback,
Fields = inAtt.Fields,
ImageUrl = inAtt.ImageUrl,
Pretext = inAtt.Pretext,
ThumbUrl = inAtt.ThumbUrl,
Title = inAtt.Title,
TitleLink = inAtt.TitleLink,
Text = ""
};
return outAtt;
}

/// <summary>
/// Post Message to Mattermost server. Messages will be automatically split if total text length > 4000
/// </summary>
/// <param name="api"></param>
/// <param name="inMessage">The messsage you wish to send</param>
/// <returns></returns>
public async Task PostAsync(IApi api, MattermostMessage inMessage)
{
try
{
var outMessages = new List<MattermostMessage>();

var msgCount = 0;

var lines = new string[] { };
if (inMessage.Text != null)
{
lines = inMessage.Text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
}

//start with one cloned inMessage in the list
outMessages.Add(CloneMessage(inMessage));

//add text from original. If we go over 3800, we'll split it to a new inMessage.
foreach (var line in lines)
{

if (line.Length + outMessages[msgCount].Text.Length > 3800)
{

msgCount += 1;
outMessages.Add(CloneMessage(inMessage));
}

outMessages[msgCount].Text += $"{line}\r\n";
}

//Length of text on the last (or first if only one) inMessage.
var lenMessageText = outMessages[msgCount].Text.Length;

//does our original have attachments?
if (inMessage.Attachments?.Any() ?? false)
{
outMessages[msgCount].Attachments = new List<MattermostAttachment>();

//loop through them in a similar fashion to the inMessage text above.
foreach (var att in inMessage.Attachments)
{
//add this attachment to the outgoing message
outMessages[msgCount].Attachments.Add(CloneAttachment(att));
//get a count of attachments on this message, and subtract one so we know the index of the current new attachment
var attIndex = outMessages[msgCount].Attachments.Count - 1;

//Get the text lines
lines = att.Text.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);

foreach (var line in lines)
{
//Get the total length of all attachments on the current outgoing message
var lenAllAttsText = outMessages[msgCount].Attachments.Sum(a => a.Text.Length);

if (lenMessageText + lenAllAttsText + line.Length > 3800)
{
msgCount += 1;
attIndex = 0;
outMessages.Add(CloneMessage(inMessage));
outMessages[msgCount].Attachments = new List<MattermostAttachment> { CloneAttachment(att) };
}

outMessages[msgCount].Attachments[attIndex].Text += $"{line}\r\n";
}
}
}


if (outMessages.Count > 1)
{
var num = 1;
foreach (var msg in outMessages)
{
msg.Text = $"`({num}/{msgCount + 1}): ` " + msg.Text;
num++;
}
}

foreach (var msg in outMessages)
{
var request = new Request("", _webhookUrl.ToString(), HttpMethod.Post);
request.AddJsonBody(msg);
await api.Request(request);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
throw;
}
}
}
}
Loading

0 comments on commit a003095

Please sign in to comment.